我有兩個具有不同構造函數的類。
有一個參數使用不同的構造函數爲不同的類創建實例
public TagService(IRepositoryAsync<Tag> tagRespository):base(tagRespository)
{
_tagRespository = tagRespository;
}
有兩個參數。
public AdsService(IRepositoryAsync<Ads> iadsRepository,IUnitOfWork unitOfWork):base(iadsRepository)
{
this._iadsRepository = iadsRepository;
this._unitOfWork = unitOfWork;
}
在開始時,我在下面使用初始化類。
//services have different constractors
Service = (TEntityService)System.Activator.CreateInstance(
typeof(TEntityService),
new object[] { _repository, _unitOfWork }
);
但是,它只對一個參數不起作用。上述情況有沒有更好的方法。我想創建一個方法,允許在構造函數中使用不同的參數創建不同的類。
XUnit Core是否支持Autofac?你能和我分享一個簡單的指南鏈接嗎?謝謝 –
它支持.net核心,所以xunit也可以。這是一個很好的鏈接:http://autofac.readthedocs.io/en/latest/getting-started/index.html – Julian