Dependency Injection With Custom Membership Provider?

May 2, 2010

I have an ASP.NET MVC web application that implements a custom membership provider. The custom membership provider takes a UserRepository to its constructor that provides an interface between the membership provider and NHibernate. The UserRepository is provided by the Ninject IoC container.

Obviously, however, this doesn't work when the provider is instantiated by .NET: the parameterless constructor does not have a UserRepository and cannot create one (the UserRepository requires an NHibernate session be passed to its constructor), which then means that the provider cannot access its data store. How can I resolve my object dependency?

It's probably worth noting that this is an existing application that has been retrofitted with Ninject. Previously I used parameterless constructors that were able to create their required dependencies in conjunction with the parametered constructors to assist unit testing.

View 3 Replies

Similar Messages:

MVC :: Dependency Injection With Custom Constraint

Jul 20, 2010

I have a custom constraint that queries a value against a repository. Is it possible to replicate the dependency injection available to controller constructors?

View 1 Replies

MVC :: Custom Authenticate Attribute With Constructor (Dependency) Injection?

Sep 7, 2010

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. terfaces 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.


I tried the following but I'm getting an error ("Object reference is required...") with "this (adGroups).


View 2 Replies

VS 2008 Implement Custom Role Provider And Membership Provider

Sep 27, 2010

I have watched the how to video on Creating a Custom Membership provider. So far it works great. My login control interacts well with it etc. Now i've created a Custom Role Provider. I've created a class that inherits the RoleProvider base class and i've added code to each Sub. My question is, what is the best way to implement the role provider, considering I get the Roles etc from the database?

View 11 Replies

Security :: Implement custom Role Provider And Membership Provider?

Dec 1, 2010

i have implemented custom role provider and membership provider .

login page : SignIn.aspx

on successful login it redirects to (index-Homepage.aspx)

now PROBLEM is when it successfully logged in ,and redirects to 'index-Homepage.aspx' it gives Anornymoustemplate ..while its verifying the role correctly in index-Homepage.aspx.cs

View 1 Replies

Security :: Custom Membership Provider Error "Could Not Load Type Custom.AspNet.Membership.PostPropertyProvider"

Jan 5, 2011

This is my first membership provider; I converted the sample provider [URL] to SQL. I created a vb class provider and put it into the App_Code folder. After it was created I tried to modify my webconfig but the error pops up. I don't know what else to try, I don't know if I have missed something



View 1 Replies

Security :: Big Extension Of Membership Provider - Should Use A New Custom Provider

Mar 27, 2010

i'm building an application and i need to manage roles, users and more things so i tought to use the membership provider but i have some questions about it: can i full extend it and can i override the functions to use a database table to store infos about config or i need to build my own provider?

View 4 Replies

Net SQL Membership Provider Custom Provider Property

Dec 16, 2010

<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
<add name="FirstName"/>
<add name="LastName"/>

I have the code snippet above in my webconfig file. I am attempting to set the FirstName property in codebehind on a register.aspx page. Like this:

Profile.FirstName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text;

VS says Profile is in System.Web.Profile Namespace. I then use it like this "System.Web.Profile.FirstName", but says first name does not exist in System.Web.Profile.FirstName namespace.

How do I set the property and later retrieve it?

View 3 Replies

Security :: Can Implement Custom MembershipUser/custom Roles And Membership Provider

Oct 13, 2010

I create custom principal for implement logic for users. In identity I store Id, Name. But it abnormally - this classes must use for authenticate and authorize.

I can implement custom MembershipUser, custom Roles and Membership provider.

How to do it? What best practices are?

View 5 Replies

Security :: Custom Membership Provider With Custom Controls?

Mar 21, 2010

I'm new to ASP.NET and I don't exactly understand some features.

I have a custom membership provider TestMembershipProvider which inherits from MembershipProvider. It has the following CreateUser method:


It's absolutely simple code.Then I have two text boxes (login, password) and the button to register a new user. I thas a following code:



Authentication in web.config is set like this:


No matter what I write into textboxes, following error is being returned:

The password retrieval question provided is invalid.

I don't know why. Either in web.config or in get RequiresQuestionAndAnswer I have false value. When I instantiate my TestMembershipProvider and call CreateUser directly instead of using static Membership.CreateUser, it works fine. Do I have to use instance of my TestMembershipProvider or did I missed anything?

View 1 Replies

C# - Dispose Of Custom Object From Within Custom Membership Provider?

Apr 16, 2010

I have created my custom MembershipProvider. I have used an instance of the class DBConnect within this provider to handle database functions. Please look at the code below:

public class SGIMembershipProvider : MembershipProvider
#region "[ Property Variables ]"
private int newPasswordLength = 8;
private string connectionString;
private string applicationName;
private bool enablePasswordReset;
private bool enablePasswordRetrieval;
private bool requiresQuestionAndAnswer;
private bool requiresUniqueEmail;
private int maxInvalidPasswordAttempts;
private int passwordAttemptWindow;
private MembershipPasswordFormat passwordFormat;
private int minRequiredNonAlphanumericCharacters;
private int minRequiredPasswordLength;
private string passwordStrengthRegularExpression;
private MachineKeySection machineKey;
**private DBConnect dbConn;**
public override bool ChangePassword(string username, string oldPassword, string newPassword)
if (!ValidateUser(username, oldPassword))
return false;
ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPassword, true);
if (args.Cancel)
if (args.FailureInformation != null)
throw args.FailureInformation;
throw new Exception("Change password canceled due to new password validation failure.");
SqlParameter[] p = new SqlParameter[3];
p[0] = new SqlParameter("@applicationName", applicationName);
p[1] = new SqlParameter("@username", username);
p[2] = new SqlParameter("@password", EncodePassword(newPassword));
bool retval = **dbConn.ExecuteSP("User_ChangePassword", p);**
return retval;
} //ChangePassword
public override void Initialize(string name, NameValueCollection config)
if (config == null)
throw new ArgumentNullException("config");
ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
if ((ConnectionStringSettings == null) || (ConnectionStringSettings.ConnectionString.Trim() == String.Empty))
throw new ProviderException("Connection string cannot be blank.");
connectionString = ConnectionStringSettings.ConnectionString;
**dbConn = new DBConnect(connectionString);
} //Initialize
} // SGIMembershipProvider

I have instantiated dbConn object within Initialize() event. My problem is that how could i dispose off this object when object of SGIMembershipProvider is disposed off. I know the GC will do this all for me, but I need to explicitly dispose off that object. Even I tried to override Finalize() but there is no such overridable method. I have also tried to create destructor for SGIMembershipProvider.

View 2 Replies

Custom Server Controls :: Get IP With Custom Membership Provider?

Feb 7, 2011

I was made a custom membership provider.

All works good. My problem is Logs.



I dont know how to get user's ip.

I tried these methods...

Dim req as httprequest
ip = req.servervariables("remote_host") 'result = nothing
Dim req as new httprequest
ip = req.servervariables("remote_host") 'result = nothing
Dim req as requestcontext
ip = req.request.servervariables("remote_host") 'result = nothing...

View 2 Replies

C# : Dependency Injection And Roles?

Jul 20, 2010

I have a page using an injected BLL service: a simple service returning a set of objects with a function like this:

public IMyService { List<Foo> All(); }

There is a default implementation for normal users.Now, i need that users in administrative role can view more objects, with another implementation of the service.Where can i configure my page to use the second implementation?

My first solution is to put the dependency to the IUnityContainer in the page, and use it to resolve the dependency:

public IUnityContainer Container { get; set;}

Page_Init(..) [code].....

it's a ServiceLocator and it's neither scalable neither testable.

View 2 Replies

C# - .NET Module Dependency Injection?

Jan 3, 2011

During the design of a new generic authentication framework for some of our products, I have come across an architectural issue I cannot seem to find a good solution for.I have tried to simplify the problem in order to easily explain it.

The library has two classes:

Manager Is responsible for storing currently authenticated users.Module It is the responsibility for the module to validate each request according to security policies. The Module must ask the manager to determine whether a user is currently authenticated.

Now the manager is supplied an implementation of an interface which allows the manager to load users from a repository. The specific implementation is not contained in this library. Because of this, I cannot directly instantiate an instance of the repository within the library.

I have no way of modifying properties or supplying arguments for the module constructor. So my question is this, how can I give the module a reference to an instance of the Manager?

namespace Demo
public interface IRepository

View 4 Replies

Dependency Injection / How To Use It In WebForms Appliction

Apr 2, 2010

as i've read Ninject is the best one so how to use it and why i cannot see good examples.

Lately i have begun learning MVC and as i've seen every one use DI in the MVC, i have a couple doesn question but i will ask a few lol...

1. Why use and what is going to do for me?

2. How to use it in WebForms Appliction ?

3. IoC is the same if not what is it and what's it doing?

4. I want to use a Ninject FrameWork 2.0 but i cannot find good examples for WebForm App.

View 4 Replies

MVC :: ModelBinder For Dependency Injection On ViewModels?

Jan 25, 2011

This project is pretty far away and I'm not in the position to go make changes all over the place (If I could, deleting the lot would be what I'd do!)

I want to create a modelbinder that would resolve any dependencies my View Models might have (using StructureMap).

It should not require me to implement a specific interface (so many developers, so many interfaces..I rather keep things clean) and hopefully not require one to go register each model binder individually (Now I'm asking too much,taking the first requirment
in consideration).

Probably will get it right tonight, but figured I'd ask.

View 3 Replies

C# - Dependency Injection - Colloquial Explanation

Apr 8, 2010

Recently I was asked to express the DI in colloquial explanation.

I answered :

1)I am going to a hotel.I ordered food.The hotel management asks me to clean the plates and
clean the tables.So here i am a client,I am responsible for managing the service (Instantiating,executing,disposing).But DI decouples such tasks so the service consumer no need not worry about controlling the life cycle of the service.

2)He also asked is there any microsoft API follows DI ?.I answered (This was my guess) In WCF you can create a Proxy using ChannelFactory that controls the life time of your factory.

for item (1) he said only 10% is correct

for item(2) he said that is factory pattern not dependency injection.

Actually what went wrong in my explanation (apart from my bad English) ? What is the real answers for those?

View 3 Replies

C# - What Dependency Injection Framework With WebForms

Nov 27, 2010

I have been looking at learning dependency injections (i think i have now grasped the basics) and am looking to implement it into a webform application. My question is, what dependency injection framework should i use for a webforms project, or is it a question of what works best for you?

I Have currently looked at Spring.Net, Ninject, Unity and StructureMap, i tend to have no preference in the configuration, whether its XML or fluent interfaces. However is XML configuration becoming less favourable?

Most of the information i come across relates to dependency injection whilst in a MVC environment. And have also read that some frameworks such as Structure Map only work with webforms using version 2.0 or earlier. So the kind of things i need to consider are whether webforms will be continuous support, and the ease of configuration for someone relatively new to the pattern.

View 1 Replies

.net - What's The Point Of Dependency Injection Frameworks

Aug 12, 2010

I am sure that I am somewhat lost in this area... my understanding is that Dependency Injection means initializing something that is required by a for instance. If my controller is going to need a service and I want to be able to test it then I should define two Constructor methods for it... so, my question is.

public class CompaniesController : Controller
private ICompaniesService _service;
public CompaniesController()

View 6 Replies

MVC :: Dependency Injection / The Role Of A 'Model'?

May 27, 2010

My general understanding of the MVC pattern is that the model is reponsible for persisting itself. Though I also see other opionions that models should be dumb data objects and that controllers should persist them via a data access layer.

Per "Many applications use a persistent storage mechanism such as a database to store data. MVC does not specifically mention the data access layer because it is understood to be underneath or encapsulated by the model." Though it does also mention "Models are not data access objects."

Per, "Models. Model objects are the parts of the application that implement the logic for the applications data domain. Often, model objects retrieve and store model state in a database. For example, a Product object might retrieve information from a database, operate on it, and then write updated information back to a Products table in SQL Server."

First, am I misguided in believing that models should persist themselves? Or, is this just a matter of opinion?

Second, if I follow the pattern where controllers manage the persistence of the model, I find it fairly easy to use dependency injection to inject a data access component into my controller using a custom controller factory (implementing the IControllerFactory
interface). If I follow the pattern where my model saves itself, I'd want to inject my data access component into the model. Is there a way to provide a custom factory for models? Otherwise, I don't think using DI with models is possible.

View 5 Replies

Dependency Injection And Code Maintainability?

Oct 30, 2010

I am working on a ( project that is using interfaces to provide dependency injection. But to me, it feels like the maintainability of the code has been killed. When I want to read through the code, I can't simply jump to the code of a related class that is used. All I see are the interfaces, and so I have to hunt through the project to figure out what classes are doing the implementation. This really hurts my productivity.

Yes, I know I now can implement the interfaces with a wide variety of replacement classes. But for example, I know I'm not changing my data source any time soon--there is no need for me to enable the ability to swap that out. All of this dependency injection seems like overkill to me (in fact, the only real reason it is there is to support mock classes for unit testing). I've actually read several places that state DI is actually better for maintainability. But that assumes you already know where everything is and you know which class you need to update. Finding out where to look is the part that is killing me. So, my question is: Is there a better way to traverse through the code? Is there a better way to make the code more maintainable? Are we just doing it wrong? Or is this par for the course?

View 2 Replies

Custom Membership Provider For Using C#?

Jun 11, 2010

How i can realise my own Membership Provider for my social network example project where i want to use more extended registration with new fields?

View 3 Replies

MVC And Custom Membership Provider?

Mar 22, 2011

i am planing an application that needs to handle different client logins. A user should be able to login under each clients url.The project will have a start page and multiple (database generated) client
I failed using MVC Routes to build up such a scenario with dynamically clients so i used an MVC area for the client Is there any client support for membership providers? All i found is made for a single client environment. I would love to take advantage of the mvc buildin attributes for authentication..

View 2 Replies

MVC :: Consume WCF Service In Application Using Dependency Injection?

Nov 11, 2010

private IGetData _getData;

View 2 Replies

Architecture :: Dependency Injection Learning Hurdle?

Jul 21, 2010

i'm just starting with mvc and specifically the repository pattern. I've read as much as i can but there doesn't appear to be a great article on dependency injection (ioc) as lots of people are doing it different. I found one article and it looks simple for setting up my data context (IDataContext) against a controller. However i have my own custom DataAnnotation attribute which
makes sure that a person's name is unique:

public class UniqueUserNameAttribute : ValidationAttribute
public override bool IsValid(object value)
string str = (string)value;

if (string.IsNullOrEmpty(str))
return true;

using (IDataContext context = new LinqToSqlDataContext())
return context.Repository<User>().Find(u => u.UserName == str).Count() == 0;

As you can see there's a hard coded dependency on my linq to sql data context. This means i can't test but i also can't see what else i can do.I'd really appreciate it if someone could point me in the right direction and recommend the best dependency injection library to use (such as StructureMap, Unity, Autofac...).

View 1 Replies

Copyrights 2005-15, All rights reserved