Autofac json configuration
2021-03-29 04:24
标签:har csharp sharp html mod divide stat file The Autofac json configuration 标签:har csharp sharp html mod divide stat file The 原文地址:https://www.cnblogs.com/ms_senda/p/12612198.html static void Main(string[] args)
{
var config = new ConfigurationBuilder();
config.AddJsonFile("autofac.json");
// Register the ConfigurationModule with Autofac.
var module = new ConfigurationModule(config.Build());
var builder = new ContainerBuilder();
builder.RegisterModule(module);
var container = builder.Build();
IOperation operation = container.Resolve
{
"defaultAssembly": "Autofac.Example.Calculator",
"components": [
{
"type": "Autofac.Example.Calculator.Addition.Add, Autofac.Example.Calculator",
"services": [
{
"type": "Auofac.Example.Calculator.Api.IOperation,Autofac.Example.Calculator"
}
],
"injectProperties": true
},
{
"type": "Autofac.Example.Calculator.Division.Divide, Autofac.Example.Calculator",
"services": [
{
"type": "Auofac.Example.Calculator.Api.IOperation,Autofac.Example.Calculator"
}
],
"parameters": {
"places": 4
}
}
]
}
public class IOperation
{
public virtual void Hello()
{
Console.WriteLine("Hello");
}
}
public class Divide : IOperation
{
public override void Hello()
{
Console.WriteLine("Hello,I‘m Divide");
}
}
public class Add : IOperation
{
public override void Hello()
{
Console.WriteLine("Hello,I‘m Add");
}
}
文章标题:Autofac json configuration
文章链接:http://soscw.com/index.php/essay/69350.html