Зарегистрируйте AutoMapper в Autofac — .Net 6 WebServiceC#

Место общения программистов C#
Anonymous
Зарегистрируйте AutoMapper в Autofac — .Net 6 WebService

Сообщение Anonymous »

В настоящее время я работаю над веб-сервисом, используя .Net6.
Я столкнулся с проблемой: я не могу зарегистрировать 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);
Мне удалось зарегистрировать другие зависимости, которые использует моя служба ISynchronizationDatabaseService

Код: Выделить всё

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

Вернуться в «C#»