How to ensure dependency injection through StructureMap for a role provider with WCF?

We are going to use a role provider with WCF. An overridden GetRolesForUser method will require the use of an existing RoleRepository.

Now, with the run-of-the-mill class, we will build it using StructureMap, and the RoleRepository dependency will be introduced through the constructor.

However, it is a WCF that builds the custom role provider class and that is "executed" declaratively through the roleManager attribute in the web.config file.

I really don't want to rigidly bind the RoleRepository role to the probvider class for the user role, but this seems to be what I need.

Any ideas?

+5
source share
1 answer

RoleProvider and its associated types are a legacy of ASP.NET, which are notorious for not being DI friendly. They require a default constructor, and there are no hooks to initialize them. It sucks, but it is.

In such situations, the best way is to implement RoleProvider as a Humble Object . In other words, RoleProvider should connect all the dependencies, but from there it delegates the entire implementation to your own open and extensible API.

+6
source

All Articles