atofac的简单使用

本文介绍了在ASP.NET MVC项目中如何使用Autofac进行依赖注入。首先,通过NuGet包管理器安装Autofac及其Configuration模块。接着,创建BUS项目,定义IOutput接口及其实现类PcWebOutput和CellPhoneOutput。通过配置文件注册组件,以实现不同类型的IOutput。示例代码展示了解析过程,并提供了下载链接以获取完整示例。
摘要由CSDN通过智能技术生成

1、新建asp.net mvc项目,安装Autofac。

【工具】---->【库程序包管理器】---->【程序包管理器控制台】

Install-package autofac  (-version 3.5.2)


2、要使用配置文件还需安装Autofac.Configuration

install-package Autofac.Configuration


3、新建项目BUS,接口:IOutput,两个实现:PcWebOutput,CellPhoneOutput,一个使用类:OutputBase

namespace Bus
{
    public interface IOutput
    {
        string Bold(string content);
    }

    public class PcWebOutput : IOutput
    {
        public string Bold(string content)
        {
            return string.Format("<b class=\"pcBlod\">{0}</b>", content);
        }
    }

    public class CellPhoneOutput : IOutput
    {
        public string Bold(string content)
        {
            return string.Format("<b class=\"cellPhoneBlod\">{0}</b>", content);
        }
    }

    publi
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值