I have a class with configuration settings. So, I want to use Simple Injector for using my config class like this:
public class Host
{
private readonly ServiceConfig _config;
public Host(ServiceConfig config)
{
_config = config;
}
}
Can I do like this?
public static class IoC
{
public static Container Container { get; set; }
public static void Configure(Container container)
{
container.Register<ServiceConfig>();
Container = container;
}
}
您应该将配置对象注册为“单个实例”:
container.RegisterInstance<ServiceConfig>(new ServiceConfig { ... });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.