Autofac依赖注入
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autofac;
using Autofac.Configuration.Core;
namespace AutoFacIOC
{
class Program
{
static void Main(string[] args)
{
//直接指定实例类型
var builder = new ContainerBuilder();
builder.RegisterType();
builder.RegisterType().As();
using (var container = builder.Build())
{
var manager = container.Resolve();
manager.Search("SELECT * FORM USER");
}
Type objType = Type.GetType("AutoFacIOC.IRepository, AutoFacIOC");
Type objTypeSql = Type.GetType("AutoFacIOC.SqlRepository, AutoFacIOC");
Type objTypeRedis = Type.GetType("AutoFacIOC.RedisRepository, AutoFacIOC");
//通过配置文件实现对象的创建
var builder2 = new ContainerBuilder();
builder2.RegisterType();
//builder.RegisterType().As();
builder2.RegisterType(objTypeSql).As(objType);
//builder.RegisterType().Named("AutofacDemo.Lib.Oracle.OracleDatabase");
//builder2.RegisterModule(new ConfigurationSettingsReader("autofac"));
using (var container = builder2.Build())
{
var manager = container.Resolve();
manager.Search("SELECT * FORM USER");
}
//通过配置文件,配合Register方法来创建对象
var builder3 = new ContainerBuilder();
builder3.RegisterType();
//builder3.RegisterModule(new ConfigurationSettingsReader("autofac"));
//builder3.RegisterType().Named("AutoFacIOC.SqlRepository");
//builder3.Register(c => new DBBase(c.Resolve()));
//builder3.RegisterType(objTypeRedis).Named("AutofacDemo.Lib.Sql.SqlDatabase", objType);
//builder3.RegisterType(objType).Named("AutoFacIOC.DBBase", objType);
builder3.RegisterType(objTypeRedis).As(objType);
using (var container = builder3.Build())
{
var manager = container.Resolve();
manager.Search("SELECT * FORM USER");
}
Console.ReadKey();
}
}
}
专业从事基于C#,WinForm ,WPF,Silverlight,WCF以及MS Sql Server 2000/2005/2008/2012 Oracle 9i/10g/11g数据库系统的ERP,CRM,企业进销存等各种数据库管理系统开发。Asp.net,Asp.net mvc,Webservice,WCF, Webapi等服务程序开发。
基于Oracle MySQL MSSql postgresql各种数据库的管理系统数据同步服务。以及基于MapXtreme, Arcgis Engine ,以及基于Arcgis for silverlight/Javascript的WebGIS等相关的GIS系统二次开发。基于Windows 10 Mobile的移动端开发方案。针对各种系统的二次开发维护,并提供相关开发的技术性支持,如程序BUG解决,应用系统架构,技术难题攻克等相关技术服务。
联系方式: QQ :80163278(devgis) 邮箱:devgis@qq.com