異なるコンストラクタを持つ2つのクラスがあります。
つのパラメータ異なるクラスのインスタンスを異なるコンストラクタで作成する
public TagService(IRepositoryAsync<Tag> tagRespository):base(tagRespository)
{
_tagRespository = tagRespository;
}
がある2つのパラメータがあります。
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 }
);
ただし、1つのパラメータでは機能しません。上記のシナリオにはよりよい方法がありますか?コンストラクタ内の異なるパラメータで別のクラスを作成できるメソッドを作成したいと思います。
AutofacはXUnit Coreでサポートされていますか?私にシンプルなガイドラインを教えていただけますか?ありがとう –
それは.netコアをサポートしているので、xunitも動作します。これは、次のリンクから始めるのに適しています:http://autofac.readthedocs.io/en/latest/getting-started/index.html – Julian