且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 IoC 成员资格提供程序与 ASP.NET MVC 集成

更新时间:2022-12-04 15:03:49

最简单的方法是在 web.config 中使用 ASP.NET 的 标准机制.您只需让它使用默认构造函数您覆盖 Initialize() 并那里的依赖项.使用这个作为参考.

The simplest way to get this to work is to use ASP.NET's standard mechanism of <membership> in web.config. You just let it use the default constructor but you override Initialize() and pull the dependencies there. Use this as reference.

就我个人而言,由于这样的事情,我更喜欢完全避免提供者模型,所以我使用了一种类似于 在 MonoRail 文档中描述.恕我直言,它不那么臃肿且更灵活.最后,它只是设置 HttpContext.User 具有适当的 IPrincipal 实现,它是AuthorizeAttribute 使用什么.

Personally, due to things like this, I prefer to avoid the provider model altogether so I use an approach similar to the ones described in the MonoRail docs. IMHO it's less bloated and more flexible. In the end, it's just about setting HttpContext.User with a proper IPrincipal implementation which is what the AuthorizeAttribute uses.

我最近写了一篇关于使用 MembershipProviders 进行适当 IoC 的解决方案的博客

I recently blogged about a solution to do proper IoC with MembershipProviders.