/// <summary> /// 通过Lambda来注册对象,可以对服务添加AOP /// <para>exp: /// Register<IMyService,MyService>(() =>{ /// var item = new MyService(); /// return item; /// });</para> /// </summary> /// <typeparam name="IT">接口</typeparam> /// <typeparam name="CT">接口实现</typeparam> /// <param name="lifeTime">生命周期</param> /// <param name="func">lambda表达式</param> /// <returns></returns> public static void Register <IT, CT>(EnumLifeTime lifeTime, Func <CT> func) { builder.Register(cc => { return(func()); }).As <IT>().SingleInstance(); LoggerService.GetInstance().LogIoCStartEventToDb(typeof(CT).Name + "注册完成!"); }
/// <summary> /// 通过接口和接口实现注册对象 /// </summary> /// <typeparam name="IT">接口</typeparam> /// <typeparam name="CT">接口实现</typeparam> /// <param name="lifeTime">生命周期</param> public static void Register <IT, CT>(EnumLifeTime lifeTime) { builder.RegisterType <CT>().As <IT>().SingleInstance(); LoggerService.GetInstance().LogIoCStartEventToDb(typeof(CT).Name + "注册完成!"); }