Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created November 5, 2019 06:18
Show Gist options
  • Save SunXiaoShan/95afc33f63a34ba9268798d33201fd08 to your computer and use it in GitHub Desktop.
Save SunXiaoShan/95afc33f63a34ba9268798d33201fd08 to your computer and use it in GitHub Desktop.
private static IContainer MiddleCompany()
{
ContainerBuilder builder = new ContainerBuilder();
//在仲介公司裡寫需求人申請單
builder.RegisterType<MineWithMiddle>();
//小明所需打掃阿姨需求
builder.RegisterType<Aunt>().As<ISwapable>();
return builder.Build();
}
IContainer middleCompany = MiddleCompany();
//仲介公司(IOC AutoFac)自動幫小明注入一個打掃阿姨
MineWithMiddle mineWithMiddle = middleCompany.Resolve<MineWithMiddle>();
mineWithMiddle.Room();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment