I have started working with Ninject for a website and setting up DI within a project.

I have noticed you register the binding dependencies within the app_start called ninjectWebCommon. When the project loads, do all dependencies get registered? For example if you have over 50 dependencies registered, will this cause resource issues? Or does each instance gets registered on page execution? If not, Is there a way to lazy bind the dependencies or is this unnecessary?

Is there a better way of accomplishing this even if using another IOC Container?

有帮助吗?

解决方案

You should read about Register Resolve Release pattern. Basically registration process is quite simple, you tell the container which types to use for resolving abstractions. No objects are created in this process. DI container creates the instances when a request hits your application. They may be created only once or on every request, depending on the life cycle.

其他提示

You do registrations like that for other containers as well and it really shouldent be a resource issue. However Ninject is a bit on the slow side. If you can choose as you like you might be better off with a DI container like SimpleInjector.

For a comparison i used a website with some benchmarks.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top