I am new to Ninject and Dependency Injection in general, so please excuse my noobility here. =)
I have several interface implementations IConfigthat scan the assembly and its dependencies for types that implement the interface IConfigOption. Each implementation IConfigextracts their values from different sources.
These implementations take the root assembly, where to start scanning as an argument to the constructor, and I'm trying to find a binding that introduces these values. So far I am thinking of something in the lines:
Bind<IConfig>().To<Config>().WithConstructorArgument("rootAssembly", target);
My problem is that I cannot find a way to get a reference to the assembly targetwhere the class will be introduced Config. Without DI, I would use Assembly.GetCallingAssembly(), but in this context, it gives the assembly where the binding is, not the target.
Also, I need a way to specify the intended implementation from the class / member that will receive the injection , so for example, client class A requests from a developer Configwho uses RoleEnvironmentand client class B requests Configwhich one uses ConfigurationManager. Here is an example to clarify the intended use:
public class Client
{
[UseApplicationConfig]
public IHelper WithAppConfig { get; set; }
[UseRoleEnvironmentConfig]
public IHelper WithRoleEnvironmentConfig { get; set; }
}
public class Helper : IHelper
{
public Helper(IConfig config)
{
}
}
I get the feeling that I'm either looking at it from the wrong angle, or I'm missing the obvious, but I'm not sure what I need to look for. What would be the best way to do this?
Many thanks.
EDIT: .