Trying to understand where to configure Automapper in a .NET 6 Function App
We are able to configure the profiles without issue:
.ConfigureServices(s =>
{
// AddAutoMapper - to load all automapper profiles
s.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
})
And the profiles look correct and function:
public class CreateRequestToBusinessMap : Profile
{
public CreateRequestToBusinessMap()
{
CreateMap<CreateRequest,Business>()
.ForMember(dest => dest.SupplierCode,
opt =>
opt.MapFrom(src => src.supplier_id))
.ReverseMap();
CreateMap<CreateRequestContact, Contact>()
.ReverseMap();
CreateMap<CreateRequestMarket, Market>()
.ReverseMap();
CreateMap<CreateRequestSubscription, Subscription>()
.ReverseMap();
}
}
Trying to figure out how to add global configurations to the .NET 6 Function App. Not sure what I am missing. We are new to Automapper but the documentation is not clear on where to add the configuration. https://docs.automapper.org/en/latest/Configuration.html
The automapper configuration is once per app domain so you should keep the automapper configuration code in the startup class in azure functions.
If you will consider an asp.net application then it should be Global.asax file.
AutoMapper also supports ASP.NET Core's dependency injection feature out-of-the-box, which we can utilise in Azure Functions.
For more information, please refer this references:
- Best Practices of AutoMapper using in Azure Functions
- AutoMapper Dependency Injection into Azure Functions