2
Friends, once again I come to you for help.
When trying to call an Action from my Controller I am 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, because I’m doing this with Automapper. Below follows my classes:
In Application Layer - Automapper Part
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, I register the Automapper service as below:
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddAutoMapperSetup();
}
What might be going on?
Help me please!