我有一个在ASP.NET 2010中开发的Web应用程序。我在ASP.NET MVC中使用了依赖注入和StructureMap。我正在尝试使用Structure Map。我正在使用
我已经构建了一个简单的启动过滤器,但是当我运行该网站时,我收到以下错误:
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
});
}
有人可以就此问题提出建议。如何解决?我真的很烦恼,需要尽快解决它。任何帮助将不胜感激。
由于
迪帕克
答案 0 :(得分:0)
我要执行以下更改: