Unity framework DependencyAttribute only works for public properties?

前端 未结 8 1211
小鲜肉
小鲜肉 2021-02-14 17:31

I was trying to clean up some accessability stuff in my code, and inadvertently broke Unity dependency injection. After a while I realized that I marked some public properties t

8条回答
  •  日久生厌
    2021-02-14 17:53

    @rally25rs, although the post is more than two years old it's still ranked high (views/google etc.) so I thought I'd add my 2 cents.. I've had the same problem and eventually chose this solution: UnityContainer and internal constructor. This is meant as a comment but I can't post comments just yet.

    You've probably seen and know this already, still it might be of use for anyone else viewing: The InternalsVisibleTo() attribute should never have worked - that's because Unity isn't calling your classes directly. Instead, it's using reflection and inspecting the Type. Of course, the Type isn't changed as a result of the attribute being there. To "enjoy" the benefits of internals visible etc. on the receiving side, you have to explicitly call the internal c'tor (or property).

提交回复
热议问题