7,765
社区成员
发帖
与我相关
我的任务
分享
//連接數據庫
var strConnectionString = Configuration.GetConnectionString ("DB");
services.AddDbContext<WZSPCMContext>(optionsBuilder => optionsBuilder.UseSqlServer(strConnectionString));
services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
services.BuildAspectCoreWithAutofacServiceProvider();
public static IServiceProvider BuildAspectCoreWithAutofacServiceProvider(IServiceCollection services, Action<IAspectConfiguration> config = null)
{
if (services == null) throw new ArgumentNullException(nameof(services));
services.AddAspectCoreContainer();
if (_otherAssembly != null)
{
foreach (var item in _otherAssembly)
{
_builder.RegisterAssemblyTypes(Assembly.Load(item));
}
}
if (_types != null)
{
foreach (var type in _types)
{
_builder.RegisterType(type);
}
}
if (_dicTypes != null)
{
foreach (var dicType in _dicTypes)
{
_builder.RegisterType(dicType.Value).As(dicType.Key);
}
}
_builder.Populate(services);
_builder.RegisterDynamicProxy(config);
_container = _builder.Build();
return new AutofacServiceProvider(_container);
}
public static T Resolve<T>()
{
return _container.Resolve<T>();
}