Register null as instance in Unity container

前端 未结 5 1371
北恋
北恋 2020-12-17 10:08

I have a repository class with optional dependency:

class MyRepository : BaseRepository, IMyRepository
{
    public MyRepository(IDataContext dataContext, IC         


        
5条回答
  •  囚心锁ツ
    2020-12-17 11:01

    In the .RegisterType() call, specify the InjectionConstructor with an OptionalParameter, as in

    .RegisterType(new InjectionConstructor(
    new ResolvedParameter(), 
    new OptionalParameter()));
    

提交回复
热议问题