开发者

How to provide dependency injection via StructureMap for a custom role provider with WCF?

开发者 https://www.devze.com 2022-12-16 06:25 出处:网络
We\'re going to be using a custom role provider with WCF.The overridden method GetRolesForUser will require the use of an already existing RoleRepository.

We're going to be using a custom role provider with WCF. The overridden method GetRolesForUser will require the use of an already existing RoleRepository.

Now, with a run-of-the-mill class, we'd const开发者_运维问答ruct it using StructureMap and the RoleRepository dependency would be injected via the constructor.

However, it's WCF that does the constructing of the the custom role provider class and that's 'done' declaritavely via the roleManager attribute in the web.config.

I don't really want to hard-wire the RoleRepository depndency into the custom role probvider class but it's looking like I'll have to.

Any ideas?


The RoleProvider and related types are legacies of ASP.NET which are infamous for not being DI-friendly. They require a default constructor and there are no hooks offered to initialize them. It sucks, but that's the way it is.

In such situations, the best remedy is to implement the RoleProvider as a Humble Object. In other words, the RoleProvider must wire up all dependencies, but from there, it delegates all implementation to your own open and extensible API.

0

精彩评论

暂无评论...
验证码 换一张
取 消