We are developing a selfhosted WCF service host which will be loading services dynamically based on configuration.
I was wondering wether I should consider each service as a mini app and use composition root in each hosted service or use composition root on the service host itself?
Your input is much appreciated!
Having a composition root per service is fine, but if you can, let your WCF service just contain 1 service with 2 methods: One method that allows you to execute query objects, one method that allows you to execute commands. This way you will still have one Composition Root for your WCF service.
To allow to do this you need to model all mutations as commands/handlers and read operations as query/handlers. When you've done this, you will never have to change anything to the SVC ever again.
Take a look at the Silverlight Cookbook, which successfully uses this approach. Take a look at the Main\Cookbook\Services.Host\CommandService.svc.cs, which is the entry point of the WCF service.
This will probably turn your world completely upside down, but this architecture is very flexible, scalable, and can lower the maintenance costs dramatically.
来源:https://stackoverflow.com/questions/10698235/di-compositionroot-with-multi-service-wcf-host