我有一个接口类:
public interface IStartUpTask
{
bool IsEnabled { get; }
void Configure();
}
Run Code Online (Sandbox Code Playgroud)
我有多个实现相同接口的类
其中一个类看起来像这样:
public class Log4NetStartUpTask : IStartUpTask
{
public bool IsEnabled { get { return true; } }
public void Configure()
{
string log4netConfigFilePath = ConfigurationManager.AppSettings["log4netConfigFilePath"];
if (log4netConfigFilePath == null)
throw new Exception("log4netConfigFilePath configuration is missing");
if (File.Exists(log4netConfigFilePath) == false)
throw new Exception("Log4Net configuration file was not found");
log4net.Config.XmlConfigurator.Configure(
new System.IO.FileInfo(log4netConfigFilePath));
}
}
Run Code Online (Sandbox Code Playgroud)
我如何告诉Ninject我希望所有实现它的类IStartUpTask自动绑定到自己?
我找到了一个使用StructureMap的例子来做到这一点,但我不知道如何在Ninject中做到这一点.
Scan(x => {
x.AssemblyContainingType<IStartUpTask>();
x.AddAllTypesOf<IStartUpTask>();
x.WithDefaultConventions();
});
Run Code Online (Sandbox Code Playgroud)