Is there a pattern for initializing objects created via a DI container

前端 未结 5 2005
轻奢々
轻奢々 2020-11-21 22:57

I am trying to get Unity to manage the creation of my objects and I want to have some initialization parameters that are not known until run-time:

At the moment the

5条回答
  •  粉色の甜心
    2020-11-21 23:13

    I can't answer with specific Unity terminology but it sounds like you are just learning about dependency injection. If so, I urge you to read the brief, clear, and information packed user guide for Ninject.

    This will walk you through the various option you have when using DI, and how to account for the specific issues that you'll face along the way. In your case, you would most likely want to use the DI container to instantiate your objects, and have that object get a reference to each of its dependencies through the constructor.

    The walkthrough also details how to annotate methods, properties, and even parameters using attributes to distinguish them at runtime.

    Even if you do not use Ninject, the walkthrough will give you the concepts and terminology of the functionality that suits your purpose, and you should be able to map that knowledge to Unity or other DI frameworks (or convince yout to give Ninject a try).

提交回复
热议问题