我有一个在 ASP.NET 2010 中开发的 Web 应用程序。我在 ASP.NET MVC 中使用了带有 StructureMap 的依赖注入。我正在尝试开始使用结构图。我在用着
我已经构建了一个简单的引导程序,但是当我运行该网站时,我收到以下错误:
StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression`1[System.Web.Mvc.IActionInvoker]。使用:类型参数“TestWebsite.Web.Controllers.Factories.InjectingActionInvoker”违反了类型参数“CONCRETETYPE”的约束。
代码块:
public static void ConfigureStructureMap()
{
ObjectFactory.Initialize(x =>
{
//registry per assembly recommended
x.AddRegistry<WebRegistry>();
x.AddRegistry<ServiceRegistry>();
x.AddRegistry<SHARE.Data.DataRegistry>();
});
//if a class needs configuring on load then this is done here. Inherit from IStartUpTask
ObjectFactory.GetAllInstances<IStartUpTask>()
.Where(x => x.IsEnabled).ToList()
.ForEach(t => t.Configure());
//This checks all is well. Not ideal to do in application_start though cause of calls to request object....
//ObjectFactory.AssertConfigurationIsValid();
}
public class WebRegistry : Registry
{
public WebRegistry()
{
For<IFormsAuthentication> ().Use<FormsAuthenticationService>();
For<IAuthentication>().Use<BasicMembership>();
Scan(x =>
{
x.AssemblyContainingType<IStartUpTask>();
x.AddAllTypesOf<IStartUpTask>();
x.WithDefaultConventions();
});
For<IActionInvoker>().Use<InjectingActionInvoker>();
SetAllProperties(c =>
{
c.OfType<IActionInvoker>();
c.WithAnyTypeFromNamespaceContainingType<UserService>(); //our services
c.WithAnyTypeFromNamespaceContainingType<AdminCookies>(); //cookie services
});
}
任何人都可以就这个问题提出建议。如何解决?我真的很困扰它,需要尽快解决它。任何帮助将不胜感激。
谢谢
迪帕克