在项目开发中,遇到一个问题,是这样的,我们有一个接口IConfiguration
public interface IConfiguration { string DefaultValue { get; } int Order { get; } }
另外有一个接口ITelemetryConfiguration继承它
public interface ITelemetryConfiguration : IConfiguration { string TelemetryValue {get; } }
现在有2个类,一个是LogLevel类,它继承IConfiguration接口. 另一个是TelemetrySupport类,它继承ITelemetryConfiguration接口。 如下
public class LogLevel : IConfiguration { private string logvalue; public string DefaultValue { get {return logvalue;} set {logvalue = value;} } public int Order { get {return 1;} } }
public class TelemetrySupport : ITelemetryConfiguration { public string DefaultValue { get { return "Enable"; } } public string TelemetryValue { get; set; } public int LoadOrder { get { return 2; } } }
在系统启动时用Autofac写的依赖注入中,我们原来是这样写的
using Autofac; using Module = Autofac.Module; public class IoCModule : Module { protected override void Load(ContainerBuilder builder) { builder.RegisterType<LogLevel>().As<IConfiguration>().SingleInstance(); builder.RegisterType<TelemetrySupport>().As<IConfiguration>().SingleInstance(); } }
标签:Autofac,string,get,ITelemetryConfiguration,IConfiguration,AsImplementedInterface From: https://www.cnblogs.com/wphl-27/p/17078314.html