IoC/DI库 SimpleInjector

码农软件 · 软件分类 · 面向方面AOP/IoC · 2019-09-29 11:41:30

软件介绍

SimpleInjector是一个基于.NET3.5的、简单易用的IoC/DI库。

SimpleInjector完全支持基于代码配置,对不太熟悉IoC/DI框架的开发人员是一种不错的选择。

使用

 

public class UserController : Controller
{
    private readonly IUserRepository repository;
    private readonly ILogger logger;

    // Use constructor injection for the dependencies
    public UserService(IUserRepository rep, ILogger logger)
    {
        this.repository = rep;
        this.logger = logger;
    }

    // implement UserController methods here.
}

配置

 

 

protected void Application_Start(object sender, EventArgs e) 
{
    // 1. Create a new Simple Injector container
    var container = new Container();

    // 2. Configure the container (register)
    container.Register();

    container.RegisterSingle(() => new CompositeLogger(
        container.GetInstance(),
        container.GetInstance()
    ));

    // 3. Optionally verify the container's configuration.
    container.Verify();

    // 4. Register the container as MVC3 IDependencyResolver.
    DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
}

 

 

 

 

 

本文地址:https://www.codercto.com/soft/d/15651.html

网红经济3.0 自媒体时代的掘金机会

网红经济3.0 自媒体时代的掘金机会

王先明、陈建英 / 当代世界出版社 / 2016-9-1 / 42

深入剖析网红经济的商业模式和整体产业链! 正在崛起的网红经济,打造出多元化的盈利模式,催生了众多新兴的产业投资机会,成为移动互联网时候的资本新风口一起来看看 《网红经济3.0 自媒体时代的掘金机会》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具