AssertConfigurationIsValid触发Owin和AutoMapper错误

时间:2014-04-27 13:57:39

标签: automapper structuremap owin

我尝试在Structure Map 3中使用新的AssertConfigurationIsValid方法来验证我的automapper配置。我有:

  Strapper.Boot(x => {
    x.AddIoc();
  });
  ObjectFactory.Container.AssertConfigurationIsValid();

AddIoc方法具有以下内容:

  ObjectFactory.Initialize(x => { x.AddRegistry(new IocRegistry()); });
  DependencyResolver.SetResolver(new IocDependencyResolver(ObjectFactory.Container));
  GlobalConfiguration.Configuration.DependencyResolver = new IocDependencyResolver(ObjectFactory.Container);
  FilterProviders.Providers.Remove(FilterProviders.Providers.Single(x => x is FilterAttributeFilterProvider));
  FilterProviders.Providers.Add(new IocFilterProvider(ObjectFactory.Container));     

IocRegistry如下:

  For<ConfigurationStore>().Singleton().Use<ConfigurationStore>().Ctor<IEnumerable<IObjectMapper>>().Is("Mapper Registry", MapperRegistry.AllMappers);
  For<IConfigurationProvider>().Use(x => x.GetInstance<ConfigurationStore>());
  For<IConfiguration>().Use(x => x.GetInstance<ConfigurationStore>());     

  For<IOwinContext>().Transient().Use(() => HttpContext.Current.GetOwinContext());
  For<DbContext>().HybridHttpOrThreadLocalScoped().Use(() => new Context());

  Scan(x => {
    x.AssemblyContainingType(typeof(IOrderHandler<>));
    x.AddAllTypesOf(typeof(IOrderHandler<>));
    x.ConnectImplementationsToTypesClosing(typeof(OrderHandler<>)); //.OnAddedPluginTypes(y => y.HybridHttpOrThreadLocalScoped());
    x.WithDefaultConventions();
  });

  Scan(x => {
    x.AssemblyContainingType(typeof(IQueryHandler<,>));
    x.AddAllTypesOf(typeof(IQueryHandler<,>));
    x.ConnectImplementationsToTypesClosing(typeof(QueryHandler<,>)); //.OnAddedPluginTypes(y => y.HybridHttpOrThreadLocalScoped());
    x.WithDefaultConventions();
  });   

我得到2个StructureMap构建错误:

结果讯息:
测试方法AuditTests.Audit_Ioc_Valid抛出异常: StructureMap.StructureMapConfigurationException:StructureMap失败:2个构建/配置失败和0个验证错误

个人资料'DEFAULT'


在实例'AutoMapper.ConfigurationStore'上构建错误     for PluginType AutoMapper.ConfigurationStore   - 和Instance'Lambda:IContext.GetInstance()'用于PluginType AutoMapper.IConfigurationProvider   - 和实例'Lambda:IContext.GetInstance()'用于PluginType AutoMapper.IConfiguration

没有注册默认实例,无法自动确定类型'AutoMapper.ITypeMapFactory' 没有为AutoMapper.ITypeMapFactory

指定配置

在实例上构建错误'Lambda:HttpContext.Current.GetOwinContext()'     对于PluginType Microsoft.Owin.IOwinContext   - 和实例'Handlers.SignInUserHandler for PluginType Plug.IOrderHandler 1[Plug.Messages.SignInUserOrder] Plug.OrderHandler 1 [Plug.Messages.SignInUserOrder]

StructureMap.Building.StructureMapBuildException:构建'Lambda:HttpContext.Current.GetOwinContext()'时失败,检查内部异常以获取详细信息 1.)Lambda:HttpContext.Current.GetOwinContext() 2.)Microsoft.Owin.IOwinContext的实例  ---&GT; System.NullReferenceException:未将对象引用设置为对象的实例。    在System.Web.HttpContextExtensions.GetOwinEnvironment(HttpContext context)    在System.Web.HttpContextExtensions.GetOwinContext(HttpContext context)    在lambda_method(Closure,IBuildSession,IContext)    ---内部异常堆栈跟踪结束---    在lambda_method(Closure,IBuildSession,IContext)    在C:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ Building \ BuildPlan.cs中的StructureMap.Building.BuildPlan.Build(IBuildSession会话,IContext上下文):第151行    在C:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ BuildSession.cs中的StructureMap.BuildSession.BuildNewInSession(输入pluginType,Instance实例):第108行    在StructureMap.Pipeline.NulloTransientCache.Get(类型为pluginType,Instance instance,IBuildSession session)中的c:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ Pipeline \ NulloTransientCache.cs:第28行    在C:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ BuildSession.cs中的StructureMap.BuildSession.ResolveFromLifecycle(输入pluginType,Instance实例):第102行    在StructureMap.SessionCache.GetObject(类型为pluginType,Instance instance,ILifecycle lifecycle)中的c:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ SessionCache.cs:第88行    在C:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ BuildSession.cs中的StructureMap.BuildSession.FindObject(Type pluginType,Instance instance):第198行    在StructureMap.Diagnostics.PipelineGraphValidator.tryBuildInstance(类型为pluginType,Instance实例,IPipelineGraph管道,ProfileReport报告)中的c:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ Diagnostics \ PipelineGraphValidator.cs:第82行 结果StackTrace:
在C:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ Diagnostics \ PipelineGraphValidator.cs中的StructureMap.Diagnostics.PipelineGraphValidator.AssertIsValid():第40行    在C:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ Diagnostics \ PipelineGraphValidator.cs中的StructureMap.Diagnostics.PipelineGraphValidator.AssertNoErrors(IPipelineGraph图):第21行    在C:\ BuildAgent \ work \ 996e173a8ceccdca \ src \ StructureMap \ Container.cs中的StructureMap.Container.AssertConfigurationIsValid():第485行

知道如何解决这两个问题吗?

谢谢你, 米格尔

0 个答案:

没有答案