views:

27

answers:

1

I am working on a library which needs to make use of the common service locator (http://commonservicelocator.codeplex.com/) to provide generic IOC support in order that we don't conflict with any consumers. Obviously I don't want to reference the IOC frameworks directly in my project but I'm unsure as to how to annotate the parts such that they can be found by the various frameworks. For instance MEF usually works by finding classes with the Export annotation and LinFu by finding classes with the Implements annotation. Both these annotations are defined within their respective projects requiring that I reference them both.

How can I get away from adding all these classes and annotating all my classes multiple times? It certainly doesn't adapt well to new IOC frameworks as a rebuild would be required for each new framework's annotations.

+2  A: 

From the documentation:

"Libraries should not configure the container"

"As a library or framework author, understand that you should not be putting anything into the container - that's the job of your caller. Allow the application writers to choose whatever container they want. You need to document what services you need registered, and if you're using the ServiceLocation.Current ambient container."

So I don't think you need to export anything, just document what you need to consume in order to run. And optionally use the ServiceLocator.Current interface to resolve any dependencies you require.

David Lynch
+1 - I agree. You could also provide a couple implementations and allow them to choose, but I don't think this is recommended.
TheCloudlessSky