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

Programming Python

Programming Python

Mark Lutz / O'Reilly Media / 2006-8-30 / USD 59.99

Already the industry standard for Python users, "Programming Python" from O'Reilly just got even better. This third edition has been updated to reflect current best practices and the abundance of chan......一起来看看 《Programming Python》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

SHA 加密
SHA 加密

SHA 加密工具