ASP.NET 코어 1.0에서는 BaseRepository
constructor 두 매개 변수를 삽입하려고합니다. 하나는 SwitchContext (아래에 등록하고 사용자 정의 매개 변수 - RepositoryCacheMode (그냥 enum))ASP.NET 핵심 종속성 주입 (선택 매개 변수 사용)
나는 이런 식으로 매개 변수를 등록하는 방법이 있습니까?
services.AddTransient<RepositoryCacheMode, RepositoryCacheMode.None>();
또는 방법 BaseRepository의 reginstration에 대한 SwitchContext의 인스턴스를 얻는 방법? BaseRepository의
public static void AddDependency(this IServiceCollection services)
{
services.AddTransient<SwitchContext, SwitchContext>();
services.AddTransient<IRepository, BaseRepository>(t => new BaseRepository(// How to get instanse of SwitchContext ? // , RepositoryCacheMode.None));
생성자 :
public BaseRepository(SwitchContext context, RepositoryCacheMode cacheMode = RepositoryCacheMode.FirstLevel)
{
Context = context;
_cacheMode = cacheMode;
}
내가 중복으로 당신을 신고 됨. 유일한 차이점은 기본값을 사용한다는 것이며, 기본값 인 null을 원한다는 것입니다. 두 가지 방법 모두 작동하지 않으며 그 이유가 설명됩니다. –