MVC organize notes 1 NET Core 3.0 used in the project AutoFac

------------ ------------ restore content begins

------------ ------------ restore content begins

useful

1.Microsoft.AspNetCore.Hosting

   ///  <Summary> 
        /// site root file
         ///  </ Summary> 
        public  static  String WebRootPath { GET . => AutofacHelper.GetService <IHostingEnvironment> () WebRootPath;}

2.Autofac

--- simple and practical https://www.cnblogs.com/wangchuang/p/12296660.html

3.Autofac.Extensions.DependencyInjection

The traditional way

Details from https://www.cnblogs.com/yanweidie/p/autofac.html

public static void Register()
{
    var builder = new ContainerBuilder();
    //注册Samoyed指定为IDog实现
    builder.RegisterType<Samoyed>().As<IDog>();
    builder.RegisterType<TibetanMastiff>().As<IDog>();
    using (var container = builder.Build())
    {
        var dogs = container.Resolve<IEnumerable<IDog>>();
        foreach (var dog in dogs)
        {
             Console.WriteLine($"名称:{dog.Name},品种:{dog.Breed}");
        }
    }
}        

Legacy: The above registration code, write their own demo when nothing issue. But the project which is very cumbersome to use, and requires its own type of registered one, the latter will provide a solution.

1. First nuget download Autofac and Autofac.Extensions.DependencyInjectionreferences

NET Core 3.0 used in the project AutoFac    https://www.cnblogs.com/lonelyxmas/p/11987155.html

 

To be a complete analysis and then to perfect supplement

Guess you like

Origin www.cnblogs.com/wangchuang/p/12564090.html