How can I use Unity with internal classes?

前端 未结 3 1467
孤城傲影
孤城傲影 2021-01-19 10:06

I have a Web API application and am using Unity for dependency injection. The application uses a library containing an Interface IDoStuff and a class that implements the int

3条回答
  •  心在旅途
    2021-01-19 10:25

    While I am personally against internal interfaces you can allow unity to use them by adding

    [assembly: InternalsVisibleTo("Unity_ILEmit_InterfaceProxies")] 
    

    to the AssemblyInfo.cs file of the project containing your interfaces. I found this after attemping to add [assembly: InternalsVisibleTo("Microsoft.Practices.Unity")] which I have seen not work in other post and had no effect, but felt it was the right direction. The stacktrace I pulled from my code referenced the assembly above and allowed the code to work.

    This would allow you to hide your Interfaces. The constructor is another story though.

提交回复
热议问题