Friends, once more I come to you for help.
When trying to call an Action from my Controller I'm getting the problem described below:
An unhandled exception occurred while processing the request. InvalidOperationException: Unable to resolve service for type 'Muo.Application.Interfaces.ICompanyService' while attempting to activate 'Muo.Presentation.Web.Controllers.CompanyController'. Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService (IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)
What seems to be the problem is in Dependency Injection. However, I'm finding it strange, as I'm doing this with AutoMapper. Here are my classes:
In Application Layer - Part of AutoMapper
public class DomainToViewModelMappingProfile : Profile
{
public DomainToViewModelMappingProfile()
{
//Transformo minha entidade numa ViewModel
CreateMap<Company, CompanyViewModel>();
}
}
public class ViewModelToDomainMappingProfile : Profile
{
public ViewModelToDomainMappingProfile()
{
//Transformo minha ViewModel em Entidade de Domínio
CreateMap<CompanyViewModel, RegisterNewCompanyCommand>()
.ConstructUsing(c => new RegisterNewCompanyCommand(c.OficialName, c.Nickname, c.Cnpj, c.Type, c.StateRegistration, c.DistrictRegistration));
CreateMap<CompanyViewModel, UpdateCompanyCommand>()
.ConstructUsing(c => new UpdateCompanyCommand(c.Id, c.OficialName, c.Nickname, c.Cnpj, c.Type, c.StateRegistration, c.DistrictRegistration));
}
}
public static class AutoMapperSetup
{
public static void AddAutoMapperSetup(this IServiceCollection services)
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddAutoMapper();
AutoMapperConfig.RegisterMappings();
}
}
In the Presentation Layer, in the Startup.cs class of the ASP.NET Core project, register the AutoMapper service as below:
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddAutoMapperSetup();
}
What could be happening?
Please help me!