Mapster Wiki上的文档不是很好,我似乎无法将它与Simple Injector连接起来。
我在下面有这个:
container.RegisterSingleton(() =>
MapperProvider.GetConfiguredMappingConfig());
container.Register<IMapper, ServiceMapper>(Lifestyle.Singleton);
public class MapperProvider
{
public static TypeAdapterConfig GetConfiguredMappingConfig()
{
var config = new TypeAdapterConfig();
return config;
}
}
错误
System.InvalidOperationException:配置无效。为类型BoutsController创建实例失败。ServiceMapper类型的构造函数包含名为"serviceProvider"、类型为IServiceProvider的参数,但IServiceProvider未注册。要解析IServiceProvider,必须在容器中注册它。
StackTrace:
at SimpleInjector.InstanceProducer.VerifyExpressionBuilding()
at SimpleInjector.Container.VerifyThatAllExpressionsCanBeBuilt(InstanceProducer[] producersToVerify)
at SimpleInjector.Container.VerifyThatAllExpressionsCanBeBuilt()
at SimpleInjector.Container.VerifyInternal(Boolean suppressLifestyleMismatchVerification)
at SimpleInjector.Container.Verify()
at Tournaments.MvcApplication.Application_Start() in F:Global.asax.cs:line 339
我不熟悉Mapster,但在浏览了ServiceMapper
源代码后,我认为以下代码可以让你与Mapster集成:
var config = new TypeAdapterConfig();
container.RegisterInstance<IMapper>(new ServiceMapper(container, config));