2
嗨我正在使用Unity作爲我的IoC容器,並試圖使用ServiceLocator獲取對象的實例。統一IRegisterAutoMapper類型沒有可訪問的構造函數
這是我試圖執行代碼:
ServiceLocator.Current.GetInstance<IAutoMapperRegisterFactory>()
我在配置文件中設置統一具有實例化對象:
container.RegisterType<IAutoMapperRegisterFactory, AutoMapperRegisterFactory>();
現在我CURENT AutoMapperRegisterFactory看起來像這個:
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;
}
}
如果我嘗試運行這個,我得到這個錯誤:
The type IRegisterAutoMapper does not have an accessible constructor.
以前我AutomapperRegisterFactory是這樣的:
public class AutoMapperRegisterFactory : IAutoMapperRegisterFactory
{
public IEnumerable<IRegisterAutoMapper> GetRegisteredAutoMappers()
{
var registeredAutoMappers = new List<IRegisterAutoMapper> { new RegisterAutoMapper(new RegisterMappings(), new RegisterCustomMappings()) };
return registeredAutoMappers;
}
}
和一切工作只是fine.What我做錯了,我該如何糾正呢?