Я столкнулся с проблемой: я не могу зарегистрировать AutoMapper.Mapper в Autofac.
Здесь вы можете увидеть мой стартап. cs
public IServiceProvider ConfigurationServices(IServiceCollection Services)
{
services.AddMvc();
Код: Выделить всё
services.Configure(x =>
{
x.ValueLengthLimit = int.MaxValue;
x.MultipartBodyLengthLimit = int.MaxValue;
});
services.AddSwaggerGen(c =>
{
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML";
string commentsFile = Path.Combine(baseDirectory, commentsFileName);
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Synchro API", Version = "v1" });
c.IncludeXmlComments(commentsFile);
});
//ADD AUTOMAPPER
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
//ADD AUTOFAC
ContainerBuilder builder = new ContainerBuilder();
//add data access module
builder.RegisterModule();
//add Service
builder.RegisterModule();
builder.Populate(services);
IContainer container = builder.Build();
return new AutofacServiceProvider(container);
Код: Выделить всё
builder.Register(c => new SynchronizationDatabaseService(c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve(),
c.Resolve()))
.As()
.EnableInterfaceInterceptors()
.InterceptedBy(typeof(ServiceExceptionHandlerBehavior))
.InterceptedBy(typeof(BusinessLogBehavior));
Код: Выделить всё
public class SynchronizationServiceController : Controller
{
private readonly ISynchronizationDatabaseService _synchronizationService;
private readonly IMapper _mapper;
public SynchronizationServiceController(ISynchronizationDatabaseService synchronizationService, Mapper mapper)
{
_synchronizationService = synchronizationService;
_mapper = mapper;
}
Подробнее здесь: https://stackoverflow.com/questions/789 ... webservice