public class Container
{
/// <summary>
/// IOC容器
/// </summary>
public static IContainer container = null;
public static T Resolve<T>()
{
try
{
if (container == null)
{
Initialise();
}
}
catch (Exception ex)
{
throw new Exception("IOC实例化出错!" + ex.Message);
}
return container.Resolve<T>();
}
public static void Initialise()
{
var builder = new ContainerBuilder();//InstancePerLifetimeScope
//builder.RegisterType< typeof(T).As<IT>().InstancePerLifetimeScope();
builder.RegisterType<LoginDAl>().As<ILoginDAL>().InstancePerLifetimeScope();
container = builder.Build();
}
}

调用的时候

private  ILoginDAL dal =Container.Resolve<ILoginDAL>();

这样调用也可以构造函数调用

相关文章:

  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2019-12-28
猜你喜欢
  • 2020-06-02
  • 2021-08-10
  • 2021-05-31
  • 2021-07-07
  • 2021-12-02
相关资源
相似解决方案