如何使用autofac注入到wcf类中

如何使用autofac注入到wcf类中,第1张

引入Autofac.Integration.Wcf

在友和高OnStart中

C# code

#region 注册各种

var builder = new ContainerBuilder()

builder.RegisterType<PetaPocoUnitOfWork>棚世().As<IUnitOfWork>().InstancePerRequest()

builder.RegisterAssemblyTypes(Assembly.Load("Att.Implement")).Where(p =>p.Name.EndsWith("Repository")).AsImplementedInterfaces()

builder.RegisterType<好尺AttService>().As<IAttService>()

container = builder.Build()

DIContainer.Initialize(container)

if (host != null)

host.Close()

host = new ServiceHost(typeof(AttService))

//重要

host.AddDependencyInjectionBehavior<IAttService>(container)

host.Open()

LoggerFactory.GetLogger().Error("服务已经启动")

#endregion

自启册运动根据项目的实体类 *** 作悄梁不同的数据库

自己写写一个wrapper。包姿首装一下dbcontext的方法

比如:wrapper.Set<T>() .where.update.delete....

set方法里面根据T创建所对应的dbcontext


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12337432.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存