我曾经使用过StructureMap,并成功通过构造函数注入将一个具体类型的仓库注入到我的控制器中,该仓库实现了一个接口。
现在,我需要将一个仓库类型注入到我的自定义成员资格提供程序中。但是如何实现呢?我的自定义成员资格提供程序是通过Membership.Provider.ValidateUser
创建的(例如)。
对于控制器,我创建了一个类似于以下代码的类:
public class IocControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(
System.Web.Routing.RequestContext requestContext,
Type controllerType)
{
return (Controller)
ObjectFactory.GetInstance(controllerType);
}
}
在
Global.asax
中的Application_Start()
方法里://...
ObjectFactory.Initialize(x =>
{
x.AddRegistry(new ArticleRegistry());
}
);
ControllerBuilder.Current.SetControllerFactory(
new IocControllerFactory());
//...
但是如何使用StructureMap在我的自定义成员资格提供程序中注入具体类型?