一、为什么使用Autofac?

    Autofac是.NET领域最为流行的IoC框架之一,传说是速度最快的一个。

    1.1、性能

    有人专门做了测试:

C# Autofac学习笔记C# Autofac学习笔记

    1.2、优点

    1)与C#语言联系很紧密。C#里的很多编程方式都可以为Autofac使用,例如可以使用Lambda表达式注册组件。

    2)较低的学习曲线。学习它非常的简单,只要你理解了IoC和DI的概念以及在何时需要使用它们。

    3)支持JSON/XML配置。

    4)自动装配。

    5)与Asp.Net MVC集成。

    6)微软的Orchad开源程序使用的就是Autofac,可以看出它的方便和强大。

    1.3、资源

    官方网站:http://autofac.org/

    GitHub网址:https://github.com/autofac/Autofac

    学习资料:Autofac中文文档

    二、数据准备

    2.1、新建项目

C# Autofac学习笔记

    IService下的接口类:

C# Autofac学习笔记
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LinkTo.Test.Autofac.IService
{
    /// <summary>
    /// 动物吠声接口类
    /// </summary>
    public interface IAnimalBark
    {
        /// <summary>
        /// 吠叫
        /// </summary>
        void Bark();
    }
}
IAnimalBark

相关文章:

  • 2022-12-23
  • 2021-11-17
  • 2021-06-19
  • 2021-12-03
  • 2021-11-01
  • 2021-04-03
  • 2021-06-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
相关资源
相似解决方案