티스토리 뷰

    // register MainViewModel and Inject ILogger
    // Is this correct? Is this how you inject a service?
        builder.RegisterType<MainViewModel>()
                   .As<ILogger>()
                              .InstancePerDependency();
                              

아니오, 이것은 정확하지 않습니다. MainViewModel ILogger 등록하고 있습니다 . 재귀적이고 충돌 가능성이있는 등록.

MainVm을 그 자체로 등록해야합니다. 저는 AutoFac에 익숙하지 않지만 간단하게 생각합니다.

    builder.RegisterType<MainViewModel>();

그러나 iirc에는 .AsSelf()확장 기능도 있습니다.

그러나 builder.RegisterAssemblyTypes(assembly).As<ILogger>();또한 잘못 보입니다. 그러면 해당 어셈블리의 모든 형식 ILogger로 등록 됩니다 . 아마도 다음과 같은 것을 원할 것입니다.

   builder.RegisterAssemblyTypes(assembly)
          .Where(...)                     // optional filter
                    .AsImplementedInterfaces();
                    


출처
https://stackoverflow.com/questions/39940145
댓글
공지사항
Total
Today
Yesterday
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30