.net - How to use/configure Unity Container IOC in my situation -
i have trouble implementing unity ioc project reading config file.
here have
1) classlibrarya
2) classlibraryb references classlibrarya
3) winforms app references classlibraryb
note: someother app reference classlibrarya, eg. web service.
classlibrarya have configured ioc depending on used. eg. idatasource different if called in web service , when called local app.
classlibraryb have own set of dependencies injected main application, in case, winforms app. classlibraryb instantiate many classlibrarya objects in loop.
winforms app contain concrete implementation of classlibraryb's dependancies implementation , container.configure should called here?
my questions are,
when , call container.configure in application?
need child container sub library tiers/layers?
should classlibraryb or winforms implement concrete class classlibrarya injected classlibrarya? should group each layer/tier's ioc config different "container" name in config file?
each application owns separate container , responsible configuring container instance. configuration , call resolve should happen close possible application's entry point. called composition root.
your windows forms application should own, configure , resolve container in bootstrapping code. there might other applications use classlibrarya totally irrelevant it.
the web service should own container , configure suit needs. knows nothing windows forms application.
here more information composition roots:
- where should injection ninject 2+ (and how arrange modules?)
- design - should objects registered when using windsor
all libraries should di container-agnostic can use container (and container instance) wire dependencies.
see here more details:
as may notice, these general principles , apply di overall - not unity.
Comments
Post a Comment