I need to enable late-binding in an application and I want to have an option to explicitly configure services using JSON configuration file.
I have an interface IDependency
and two classes DependencyOne
and DependencyTwo
which both implement the interface. I also have a SomeService
class that has a constructor with following signature:
public SomeService(IDependency dependency1, IDependency dependency2)
I want to inject DependencyOne
for dependency1
, and DependencyTwo
for dependency2
.
How can I configure that purely in JSON configuration, without using any attributes in the code? Is it possible at all?
The no-attribute requirement is needed because the late-bound assembly is not supposed to depend on AutoFac.
Thanks in advance.
Update: solution
Travis' answer below contains a link to FAQ which led me to acceptable solution. Use "marker" interfaces, e.g. IDependencyOne : IDependency
and IDependencyTwo : IDependency
, and then SomeService(IDependencyOne dependency1, IDependencyTwo dependency2)
. The thing I don't like so much is that now a generic decorator for IDependency
needs to implement all markers, say LoggingDecorator : IDependencyOne, IDependencyTwo
if I want to use it in SomeService
, but as long as the markers stay empty, that's not a big problem. This way I don't have to enforce dependency on Autofac's dlls in the late-bound assembly, while still have DI configured in JSON file.