using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac.Builder;
using Autofac.Configuration;
using Autofac;
/// by rhythmk
namespace AutofacApp
{
class Program
{
static void Main(string[] args)
{
var builder = new ContainerBuilder();
builder.RegisterType<DBManage>();
builder.RegisterType<sqlDB>().As<IDataBase>();
//using (var container=builder.Build(ContainerBuildOptions.Default))
//{
var container = builder.Build(ContainerBuildOptions.Default);
var manage = container.Resolve<DBManage>();
manage.Select();
manage.Update();
//}
Console.ReadKey();
}
}
public interface IDataBase
{
void Update();
void Select();
}
public class sqlDB : IDataBase
{
#region IDataBase 成员
public void Update()
{
Console.WriteLine("sqlDB Update");
}
public void Select()
{
Console.WriteLine("sqlDB Select");
}
#endregion
}
public class MysqLDB : IDataBase
{
#region IDataBase 成员
public void Update()
{
Console.WriteLine("MysqLDB Update");
}
public void Select()
{
Console.WriteLine("MysqLDB Select");
}
#endregion
}
public class DBManage
{
private IDataBase _dataBase;
public DBManage(IDataBase m_dataBase)
{
this._dataBase = m_dataBase;
}
public void Update()
{
this._dataBase.Update();
}
public void Select()
{
this._dataBase.Select(); } }}