• Autofac 依赖注入


    简单了解:https://www.cnblogs.com/WeiGe/p/3871451.html

     项目代码:GitHub

    owin+webapi中使用Autofac:

    添加Nuget包:

    Autofac
    Autofac.WebApi2.Owin

    owin中添加:

     //注册依赖注入
                ContainerBuilder builder = new ContainerBuilder();
                // Register your Web API controllers.
                builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
                
                builder.RegisterType<JwtUserRepository>().As<IJwtUserRepository>();
                builder.RegisterType<JwtUserService>().As<IJwtUserService>();
    
                // Run other optional steps, like registering filters,
                // per-controller-type services, etc., then set the dependency resolver
                // to be Autofac.
                IContainer container = builder.Build();
                config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
    
                // OWIN WEB API SETUP:
    
                // Register the Autofac middleware FIRST, then the Autofac Web API middleware,
                // and finally the standard Web API middleware.
                app.UseAutofacMiddleware(container);
                app.UseAutofacWebApi(config);

    ①在Repository 仓储中写逻辑代码,Service  应用中调用仓储代码

    列如:

     

    ②webapi中

  • 相关阅读:
    NPOI 操作 excel 帮助类
    文件帮助类
    浮点数精度问题
    多段文本显示省略号
    数字排序
    删除字符串首位空格
    生成一定范围的随机数
    锚链接动画
    原生js转json
    弹出遮罩和对话框
  • 原文地址:https://www.cnblogs.com/Sea1ee/p/10980025.html
Copyright © 2020-2023  润新知