参考地址:https://docs.autofac.org/en/latest/examples/index.html 1. nuget :Autofac.Extensions.DependencyInjection Autofac.Extras.DynamicProxy 2. using System.IO; using Autofac.Extensions.DependencyInjection; using Microsoft.AspNetCore.Hosting; using Micro
DI 1.0 -- 通过 RegisterInstance 注入 一开始,并不是很懂 AutoFac 的用法,又因为要使用特定的构造器和参数来初始化 DbContext,所以我想到的办法就是使用 RegisterInstance,代码如下: var optionsBuilder = new DbContextOptionsBuilder<BookListDbContext>(); optionsBuilder.UseMySql(connectionString, b => b.Migra
using Autofac;using Autofac.Builder;using Autofac.Core; //实现Autofac扩展 public static AutofacRegisterWcf { public static IRegistrationBuilder<TServiceContract, SimpleActivatorData, SingleRegistrationStyle> RegisterWcfServiceContract<TServiceContrac
private static void SetAutofacWebAPI() { var builder = new ContainerBuilder(); #region 配置注册方法 string dataType = ConfigurationManager.AppSettings["dataBaseType"].ToString().ToLower(); //var data = Assembly.Load("Model");//加载特定程序集 var da
using Autofac; using IService; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using TT.Service.Interface; using TT.Service.Realize; namespace InjectionServe
创建实例方法 1.InstancePerDependency 对每一个依赖或每一次调用创建一个新的唯一的实例.这也是默认的创建实例的方式. 官方文档解释:Configure the component so that every dependent component or call to Resolve() gets a new, unique instance (default.) 2.InstancePerLifetimeScope 在一个生命周期域中,每一个依赖或调用创建一个单一的共享的