//注入接口与实现类关系
public void ContainerInJection()
{
ContainerBuilder containerBuilder = new ContainerBuilder(); //创建:ioc容器对象
Assembly InterfaceAssembly = Assembly.LoadFrom("Interfaces.dll"); //接口程序集
Assembly serviceAssembly = Assembly.LoadFrom("Services.dll"); //实例类程序集
containerBuilder.RegisterAssemblyTypes(InterfaceAssembly, serviceAssembly).AsImplementedInterfaces(); //建立程序集关系
IOC.IOCS = containerBuilder.Build(); //获取关系,保存到集合
}
//给属性赋值
private static IMicrophone _IMicrophone;
public static IMicrophone IMicrophone
{
get
{
if(_IMicrophone == null)
{
_IMicrophone = IOC.IOCS.Resolve < IMicrophone > ();
}
return _IMicrophone;
}
}
//直接调用方法 Registration.IMicrophone.GenerateEntityClass("123");