I have an existing ASP.NET MVC application and am using StructureMap as my IOC container of choice. Currently when a controller needs an IMembershipProvider I use StructureMap to inject a concrete instance in the controller's constructor based on the BuyerMembershipProvider configuration from my web.config file as in the below solution code:
ObjectFactory.Initialize(x =>
{
x.ForRequestedType<IMembershipService>().TheDefaultIsConcreteType<AccountMembershipService>();
x.ForRequestedType<IFormsAuthentication>().TheDefaultIsConcreteType<FormsAuthenticationService>();
x.ForRequestedType<MembershipProvider>().TheDefault.IsThis(SecurityProvider.Providers["BuyerMembershipProvider"]);
});
This works fine. However, it is bound to the "buyer" user type. Seller information is stored in a different database and will have different tables to store membership information. Essentially, I would like to be able to inject either a BuyerMembershipProvider or a SellerMembership Provider based on context and have the following in my objectfactory initialization:
x.ForRequestedType<MembershipProvider>().TheDefault.IsThis(SecurityProvider.Providers["BuyerMembershipProvider"]);
x.ForRequestedType<MembershipProvider>().TheDefault.IsThis(SecurityProvider.Providers["SellerMembershipProvider"]);
Is it possible to decide between two concrete implementations when initializing the objectfactory?
Any help is greatly appreciated, Thanks in advance! JP