.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Custom Authenticate Attribute with Constructor (Dependency) Injection

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :ASP.Net
  I have a [BeastAuthenticate] attribute on my controller.  The following code works fine but I would like to use Contructor (Dependency) Injection with Unity.  The problem is that the attribute will run the contructor with no parameters.  Interfaces ITMSLogger and IADGroups are setup to use Dependency Injection with TMSLogger and ADGroups respectively.   The following code works fine but doesn't use dependency injection for class ADGroups. public class BeastAuthenticateAttribute : AuthorizeAttribute { private ITMSLogger logger = new TMSLogger(); public BeastAuthenticateAttribute() { ADGroups adGroups = new ADGroups(logger); Roles = adGroups.GetRolesWithGroup("BEAST"); } } I tried the following but I'm getting an error ("Object reference is required...") with "this (adGroups). public class BeastAuthenticateAttribute : AuthorizeAttribute { private ITMSLogger logger = new TMSLogger(); private IADGroups adGroups;// = new ADGroups(new TMSLogger()); public BeastAuthenticateAttribute() : this (adGroups) { // adGroups = new ADGroups(logger); // this(adGroups); } public BeastAuthenticateAttribute(IADGroups adGroups) { //ADGroups adGroups = new ADGroups(l

View Complete Post

More Related Resource Links

Inside Microsoft patterns & practices: Dependency Injection in Libraries


This article discusses how to write a library or framework that uses the Dependency Injection pattern and how the change in focus affects the usage of the pattern.

Chris Tavares

MSDN Magazine November 2009

Design Patterns: Dependency Injection


Today there is a greater focus than ever on reusing existing components and wiring together disparate components to form a cohesive architecture. But this wiring can quickly become a daunting task because as application size and complexity increase, so do dependencies.

Griffin Caprio

MSDN Magazine September 2005

UserControl, CustomControl Design Time Support errors IOC, Dependency Injection, MVP

  Hi, is there a way to completely disable design time support for CustomControl, and UserControl ? I have about 30 UserControls and 10 CustomControls in my WinForms app, which contains some Dependency Injections and IOC stuff in constructors and Load handlers. I have lots of large UserControls containing smaller UserControls (CompositeView). All my UI code is pretty dynamic and the only thing i need to do at design time is to drag&drop containers in other containers (UserControls). And now i have a hard time doing this, because i have to wrap all constructors and Load Handlers in CurrentProccess!="devenv"... and when I'm Implementing some new View interface (which consist lots of properties) in UserControl all those properties by default throw NotImplementedException and i don't always need to implement them immediately but still i need to be able to run this code for testing. Besides, then i have to clean up designer generated class because it adds unnecessary null value property initializations, and then it way add some other ____ code, and so on.... Imagine UserControl with 10-15 nested UserControls, and then i try to open it in Form Designer and get ObjectReference NULL exception (for IOC) or some NotSupported NotImplemented exceptions (for properties) without adequate CallStack available! There is a CallStack but there is no trace in it to my Code (

Custom Validation Attribute is not called by validation mechanism.

Hello everyone I have create custom validation attribute and assign it to class level validation. Unfortunately, it is not called. I try every way that it think it could be solve the problem. However, it take me for hours and I can't find the attribute is not called by validation mechanism.For illustrate you I put the following code.Attribute[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public sealed class BooleanDependencyAttribute : ValidationAttribute { private const string _defaultErrorMessage = "?????????{0}"; private readonly object _typeId = new object(); public string DependencyPropertyName { get; private set; } public string DependentPropertyName { get; private set; } public BooleanDependencyAttribute(string dependencyPropertyName, string dependentPropertyName) : base(_defaultErrorMessage) { DependencyPropertyName = dependencyPropertyName; DependentPropertyName = dependentPropertyName; } public override object TypeId { get { return _typeId; } } public override string FormatErrorMessage(string name) { return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString,name); } public override bool

how to read a custom dynamic data meta data attribute in a field template

All --Please help.I need to know how to read a custom dynamic data meta data attribute in a field template.I know how to do it in a page template because I have a handle to the meta table on the page.However, I do not know how to get a handle to the meta column at run time in a field template.Can you help?Please advise.Thank you.-- Mark Kamoski

Custom Model Binder Attribute

Hello,I have the following custom model binder attribute: public class DateTimeAttribute : CustomModelBinderAttribute { public DateTimeAttribute(String date, String time) { _binder = new DateTimeModelBinder { Date = date, Time = time }; } // DateTimeAttribute public override IModelBinder GetBinder() { return _binder; } // GetBinder } // DateTimeAttributeHowever, when I use it as follows:[AcceptVerbs(HttpVerbs.Get), DateTime("Date", "Time")] public virtual ActionResult Create() { // ... }I get the following error:Attribute 'MyApp.DateTime' is not valid on this declaration type. It is only valid on 'class, struct, enum, interface, param' declarations.What am I missing?I am using MVC 3.Thanks,MiguelError 5 Attribute 'FlyOnDreams.Net.Mvc.DateTime' is not valid on this declaration type. It is only valid on 'class, struct, enum, interface, param' declarations. C:\Users\Miguel\Projects\Fly On Dreams Lab\Fly On Pages\Solution\Trunk\Source\FlyOnDreams.FlyOnPages.Presentation\Areas\FlyOnPages\Controllers\UserController.cs 46 46 FlyOnDreams.FlyOnPages.Presentation

Custom validation attribute that compare 2 valaues

I want to create Custom validation attribute  that compare 2 valaues i wnat to get the two vlaue   in side the validator together sucha that i have check  2 conditions 1)if the values of the two fieds are 0 then no need to do any comparison else value 1 should be less than value 2 MVC2  

Custom Workflow Activity dependency property FieldNames

I have a custom actvity in VS2008. All is well until I added a new dependancy property like so: public static DependencyProperty EventLookupColumnNameProperty = DependencyProperty.Register("EventLookupColumnName",typeof(string),typeof(FTFSyncEventToAttachmentListItem)); public static DependencyProperty EventLookupColumnIDProperty = DependencyProperty.Register("EventLookupColumnID",typeof(string),typeof(FTFSyncEventToAttachmentListItem)); [Description("Event Lookup Column Name")][DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)][Browsable(true)][ValidationOption(ValidationOption.Required)]public string EventLookupColumnName{get { return ((string)(base.GetValue(EventLookupColumnNameProperty))); }set { base.SetValue(EventLookupColumnNameProperty, value); } [Description("Event Lookup Column ID")][ValidationOption(ValidationOption.Required)][Browsable(true)][DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]public int EventLookupColumnID{get { return ((int)(base.GetValue(EventLookupColumnIDProperty))); }set { base.SetValue(EventLookupColumnIDProperty, value); }}Then in the actions file:    <Action Name="FTF Sync Event To Attachment List Item"   ClassName="DP.Sharepoint.Workflow.FTFSyncEventToAttachmentListItem"   Assembly="DP.Sharepoint.Workflow, Version=, Cultur

Allow System.Enum and System.ValueType as parameter types in a custom attribute

This is a continuation from a Microsoft Connect posting: https://connect.microsoft.com/VisualStudio/feedback/details/507907/error-an-attribute-argument-must-be-a-constant-expression-etc-incorrectly-received-when-the-argument-is-of-type-enum I am replying to Karel Zikmund’s latest posting, dated 29/07/2010 at 12:57.   Thank you for your response Karel, but once again, I am afraid you are wrong: > > This is irrelevant: the same is true irrespective of whether the parameter type is System.Enum or System.Object. > It is actually relevant - Think how IL code for this code should look like: >    void MyMethod(System.Enum arg) { System.WriteLine(arg); } >    MyMethod(MyInt1Enum.One); >    Mymethod(MyInt4Enum.Two); I’ve looked at the generated IL. It looks exactly the same as it does if I change the parameter type to System.Object. This is also what I expected. What IL did you expect to be generated? > System.Object is passed by reference which is a fixed size (4 or 8 bytes on x86 or x64 arch respectively). Yes, and so is System.Enum (and System.ValueType). > Enums and value types are passed by value (unless they are boxed) and their size therefore has to be known at JIT time. Yes, but System.Enum and System.ValueType are both neither an enum type nor a value type — they are both reference types that

How to get field name in the custom attribute?



     How to get field name in the custom attribute?


  [Filter(FilterControl = "Cascade")]
  public object Product { get; set; }

In the codes of FilterAttribute ,How to get field name?(this is "Product")


Can you add Dependency Properties to custom activities?


I'm trying to add a simple DependencyProperty to a base activity of mine that inherits from NativeActivity.  Is this possible?  It doesn't seem so since the SetValue and GetValue methods of the dependency property definition are not recognized.

I want a dependency property because I'd like to be able to check the property from a Trigger in the activity designer ... like this:

            <Trigger Property="{Binding Path=ModelItem.IsEnabled}" Value="True">
              <Setter TargetName="Header" Property="<

SQL Injection Walkthrough / Tutorial

SQL Injection is a trick to inject SQL query/command as an input possibly via web pages. Many web pages take parameters from web user, and make SQL query to the database. Take for instance when a user login, web page that user name and password and make SQL query to the database to check if a user has valid name and password. With SQL Injection, it is possible for us to send crafted user name and/or password field that will change the SQL query and thus grant us something else.

Custom Controls in C# .NET

Embedding user controls in a Windows form is just like adding a simple button or text box that are already provided with .NET. These basic controls were written essentially like you code your own controls. Typically the controls you design are to be used in multiple forms or to modularize your code. These reasons help reduce the amount of code you have to type as well as make it easier for you to change your implementation. There should almost never be any reason to duplicate code because it leaves a lot of room for bugs. So, implementing functionality specific to your control in the control's source code is a good idea. This reduces code duplication as well as modularize your code, which is a good programming guideline.

Writing custom MembershipProvider

ASP.NET Membership mechanism allows to use the build-in server tables to store and retrieve user data. By default, this mechanism can only be used with SQL Server database to which Microsoft provides suitable MembershipProvider class.
Inheriting from this abstract class, developer can use his own table(-es) from any database and use any database engine other than SQL Server, like Oracle, DB2 etc.

Custom Editing Behavior for DataGridView TextBox Columns

For various reasons I'm using a DataGridView instead of a ListView, and while configuring the DataGridView to look like a ListView wasn't much of a problem, there's one thing that got on my nerves, which is the behavior of textbox cells in edit mode: It is much too easy to leave the edit mode accidentally, simply by pressing the cursor keys at the wrong time. For example when the text caret is positioned behind the last character of the textbox cell content, and you press the right arrow key

Write Custom WebParts for SharePoint 2007

The popularity of SharePoint Portal Server 2003 led Microsoft to tightly integrate the next SharePoint version, Microsoft Office SharePoint Server (MOSS) 2007, with its ASP.NET 2.0 WebPart framework. This tight integration enables the ASP.NET and SharePoint developer to do a number of things that previously weren't possible

Writing Custom Web Parts for SharePoint 2007

As I mentioned in an earlier blog post, SharePoint 2007 is built on top of ASP.NET 2.0, which means you can now use ASP.NET 2.0 features (Forms Authentication, Master Pages, Membership, Site Navigation, New Data Controls, etc) when building SharePoint sites. This is true for both the new Windows SharePoint Services 3.0 version (which will be a free download) as well as Microsoft Office SharePoint Server 2007 (which costs money).
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend