Lazy Dependency Injection

前端 未结 3 1324
一个人的身影
一个人的身影 2020-12-08 21:30

I have a project where the Ninject is used as IoC container. My concern is that a lot of classes have such kind of constructors:

[Inject]
public HomeControll         


        
3条回答
  •  半阙折子戏
    2020-12-08 21:32

    Steven is correct in saying that this looks like premature optimization. The construction of these object is very fast and is usually never the bottleneck.

    However using Lazy to express a dependency you don't need right away is a common pattern in Dependency Injection frameworks. Actofac is one such container that has built in support for various wrapping types. I'm sure there is also an extension for Ninject as well, maybe take a look at this one, Ninject Lazy.

提交回复
热议问题