Hi I am using Unity as my IoC container and am trying to get an instance of an object using ServiceLocator.
This is the code I am trying to execute:
ServiceLocator.Current.GetInstance<IAutoMapperRegisterFactory>()
I have set in my configuration file the object that unity has to instantiate:
container.RegisterType<IAutoMapperRegisterFactory, AutoMapperRegisterFactory>();
Now my curent AutoMapperRegisterFactory looks something like this:
public class AutoMapperRegisterFactory : IAutoMapperRegisterFactory
{
private readonly IRegisterAutoMapper m_RegisterAutoMapper;
public AutoMapperRegisterFactory(IRegisterAutoMapper registerAutoMapper)
{
m_RegisterAutoMapper = registerAutoMapper;
}
public IEnumerable<IRegisterAutoMapper> GetRegisteredAutoMappers()
{
var registeredAutoMappers = new List<IRegisterAutoMapper> { m_RegisterAutoMapper };
return registeredAutoMappers;
}
}
And if I try to run this I get this error:
The type IRegisterAutoMapper does not have an accessible constructor.
Previously my AutomapperRegisterFactory looked like this:
public class AutoMapperRegisterFactory : IAutoMapperRegisterFactory
{
public IEnumerable<IRegisterAutoMapper> GetRegisteredAutoMappers()
{
var registeredAutoMappers = new List<IRegisterAutoMapper> { new RegisterAutoMapper(new RegisterMappings(), new RegisterCustomMappings()) };
return registeredAutoMappers;
}
}
And everything worked just fine.What am I doing wrong and how can I correct it?