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F3XTj0SDCfQn/DoP8hScvbsJdYeArhzunn25L/kh07eYmE9aVGy/et5RkO65sqKgtAACY8Ze7vtn0y9P/9OtTh35zcuBfT8f/v5BayXu8evDF02DQRlkcBpO1sI4UNTVmPfirIO8d7+uB+/B46TtD5O8spTHrFc1KNHdUFeLXlcDjO5UFtWFdebJnaM+6rVlh4h1XQrn/7ZH/axYACk53walWqz8NedGzjjaiZx0tJfasS8KfBgMAQAu88Z8nI0QsSFiHUYR1AACAFBDWYQLDYAAAAJKjZx1Gna096+edd572/RdffHHPnj3TdP9xKWEdAACkjrAOo87KsH7hhRfu2bNH+/7BgwcbLt72TzUAAJh6COswIbvDYB544IFisfjqq6/OnTv3iiuuWL9+vWVZPT09S5cuffTRRz/++OPNmzdPnz59586d+/btO3ToUEdHx8MPP/zJJ588+OCDd9555+7du1977bWrrrpq2rRphUJh3759g4ODhHUAAJAuetZhVHZ71s8///xLLrlk3bp1d9xxx9VXX/3EE09YlrVmzZqenp5Zs2bt3bvXsqzVq1evXbvWsqxbbrkln89fdNFFw8PD7rKzZ89evXp1Pp9ftGjRli1bLMuaM2cOYR0AAKSLsA6jshvWn3/++a1bt+7du7evr2/+/PnasJ7L5ZYvX25Z1rx584aGhmbPnu2G9c2bN2/fvn379u2bNm3q6em5++67GQYDAACMIqzDhIwOgznnnHPeeeedWbNmDQwM9PX1zZ0799ChQ3PmzDl48GBPT8+MGTOOHDkyc+bMpUuXbtu2bcaMGY888siqVau8sH706NGLL774vvvu27RpU1dX14EDB2bOnHnDDTcQ1gEAQLroWYdR2e1Zv/nmmwuFQk9Pz7x58yzLuuuuu55++umlS5deeeWVlmXdf//9GzdutCyrr69v+/btfX1906ZNmz59+m233WZZ1qJFi5599tlbb7118eLFlmXdfvvtQ0ND7p8I6wAAIEWEdRiV3bBu7tX2TzUAAJh6COswIaPDYKZyWB92bMcpDgfeLzlOxeltd0PTNmfb7pcdJ5/KqsLOh7YUJkVp7FdCkziXypMvcxt3vL3FSHWLxYrjOE651O5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amrXOdInjFhob0/wlDnfpnzLgLajZx1G0bMOAACQHGEdRhHWAQAAUkBYhwkMgwEAAEiOnnUYRc86AABAcoR1GEVYBwAASAFhHSYwDAYAACA5etZhFD3rAAAAyRHWYRRhHQAAIAWEdZjAMBgAAIDk6FmHUfSsAwAAJEdYh1GEdQAAgBQQ1mECw2AAAACSo2cdRtGzDgAAkBxhHUYR1gEAAFJAWIcJDIMBAABIjp51GEXPOgAAQHKEdRhFWAcAAEgBYR0mMAwGAAAgOXrWYRQ96wAAAMkR1mEUYR0AACAFhHWY0NJhMB3Lcx3Lc0wwwQQTTDDBBBNTbKKbsA4zGLMOAACQAsI6TCCsAwAApICwDhNaEdbbvpMAAACmEdZhAmEdAAAgBYR1mPD/L+WkAOnhWmoAAAAASUVORK5CYII=" alt="" />
2.配置注入规则(Global.asax)
using Autofac;
using Autofac.Integration.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing; namespace BestExpress
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles); #region Autofac注入依赖
var builder = new ContainerBuilder();
SetupResolveRules(builder);
builder.RegisterControllers(Assembly.GetExecutingAssembly());
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
#endregion
}
private static void SetupResolveRules(ContainerBuilder builder)
{
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where(t => t.Name.EndsWith("Service"))
.AsImplementedInterfaces();
//注册泛型规则
builder.RegisterGeneric(typeof(EntRegCRUDService<>)).As(typeof(ICRUDService<>)); }
}
}
crud注入Controller
private ICRUDService<X6_EntryRegistration> _crud;
public X6_EntryRegistrationController(ICRUDService<X6_EntryRegistration> crud)
{
_crud = crud; }
//基于SqlSugarOrm的依赖注入:
interface:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace EntryRegistration.Models
{
public interface IDBService<T> : IDisposable
{
T GetDBInstance();
}
}
//实现类
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace EntryRegistration.Models
{
public class SqlServerService : IDBService<SqlSugarClient>
{
public SqlSugarClient _db;
public SqlServerService()
{
string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
_db = new SqlSugarClient(ConnectionString);//获SqlSugarClient对象
}
public SqlSugarClient GetDBInstance()
{
return _db;
}
public void Dispose()
{
if (_db != null)
{
_db.Dispose();
}
} }
}
在控制器中的注入:
private SqlSugarClient _db;
public ViewController(IDBService<SqlSugarClient> db)
{
_db = db.GetDBInstance();
}
CRUD:
//interface
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc; namespace EntryRegistration.Models.CRUD
{
public interface ICRUDService<T>
{
/// <summary>
/// 添加
/// </summary>
/// <returns></returns>
ActionResult Add(T obj); /// <summary>
/// 删除
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
ActionResult Del(Guid VGUID); /// <summary>
/// 编辑
/// </summary>
/// <param name="obj">当前类型实例</param>
/// <returns></returns>
ActionResult Edit(T obj); /// <summary>
/// 通过主表ID查列表
/// </summary>
/// <param name="EntryRegistrationID"></param>
/// <returns></returns>
ActionResult Select(Guid EntryRegistrationID);
}
}
//实现类
using Best.Entities.Tables;
using EntryRegistration.Models.CRUD;
using EntryRegistration.Models.Entity;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc; namespace EntryRegistration.Models.CRUD
{
public class EntRegCRUDService<T> : ICRUDService<T> where T : class, new()
{ private SqlSugarClient _db; public EntRegCRUDService(IDBService<SqlSugarClient> db)
{
_db = db.GetDBInstance();
} /// <summary>
/// 添加方法实现
/// </summary>
/// <param name="obj"></param>
/// <returns>Json结果</returns>
public ActionResult Add(T obj)
{
ActionResultModel<string> result = new ActionResultModel<string>();
try
{
if (typeof(T) != typeof(X6_EntryRegistration))
{
obj.GetType().GetProperty("VGUID").SetValue(obj, Guid.NewGuid());
}
#region 数据验证
//必填验证
CheckResult checkResult = Models.Check.CheckRequire<T>(obj);
if (checkResult.isSuccess != true)
{
return JsonHandle.GetResult(false, checkResult.msg);
}
#endregion
//数据插入
var IsSuccess = _db.Insert(obj);
if (IsSuccess.ToString() == "true")
{
return JsonHandle.GetResult(true, "数据插入成功");
}
else
{
return JsonHandle.GetResult(false, "数据插入失败");
}
}
catch (Exception ex)
{
result.isSuccess = false;
result.responseInfo = ex.Message;
}
return JsonHandle.GetResult(result.isSuccess, result.responseInfo);
}
/// <summary>
/// 删除方法实现
/// </summary>
/// <param name="VGUID"></param>
/// <returns>Json结果</returns>
public ActionResult Del(Guid VGUID)
{
ActionResultModel<string> result = new ActionResultModel<string>();
try
{
bool isSuccess = _db.Delete<T, Guid>(VGUID);
if (isSuccess == true)
{
return JsonHandle.GetResult(true, "删除成功");
}
else
{
return JsonHandle.GetResult(false, "删除失败");
}
}
catch (Exception ex)
{
result.isSuccess = false;
result.responseInfo = ex.Message;
}
return JsonHandle.GetResult(result.isSuccess, result.responseInfo);
}
/// <summary>
/// 编辑方法实现
/// </summary>
/// <param name="obj"></param>
/// <returns>Json结果</returns>
public ActionResult Edit(T obj)
{
ActionResultModel<string> result = new ActionResultModel<string>();
try
{
var VGUID = obj.GetType().GetProperty("VGUID").GetValue(obj, null);
bool isSuccess = _db.Update<T, Guid>(obj, Guid.Parse(VGUID.ToString()));
if (isSuccess == true)
{
return JsonHandle.GetResult(true, "更新成功");
}
else
{
return JsonHandle.GetResult(false, "更新失败");
}
}
catch (Exception ex)
{
result.isSuccess = false;
result.responseInfo = ex.Message;
}
return JsonHandle.GetResult(result.isSuccess, result.responseInfo);
}
/// <summary>
/// 查询方法实现
/// </summary>
/// <param name="EntryRegistrationID"></param>
/// <returns>Json结果</returns>
public ActionResult Select(Guid EntryRegistrationID)
{ var list = _db.SqlQuery<T>("select * from " + typeof(T).Name + " where EntryRegistrationID=@EntryRegistrationID", new
{
EntryRegistrationID = EntryRegistrationID
})
.ToList();
return JsonHandle.GetResult(list); } }
}
Asp.net mvc中应用autofac的更多相关文章
- Ioc容器Autofac系列(2)-- asp.net mvc中整合autofac
经过上篇蜻蜓点水的介绍后,本篇通过实例快速上手autofac,展示当asp.net mvc引入了autofac之后会带来什么. 创建Asp.net MVC并引入Autofac 首先,创建一个MVC站点 ...
- Asp.net mvc中整合autofac
创建Asp.net MVC并引入Autofac 首先,创建一个MVC站点,为方便起见,选初始带HomeController和AccountController的那种.然后通过NuGet或到Autofa ...
- asp.net MVC中使用Autofac小结 (遇到的最傻错误: 没有为该对象定义无参数的构造函数)
项目使用的MVC4,.net 4.5 Nuget安装最新的autofac,一直提示不支持.net 4.5.没办法了,最后用Nuget控制台安装的老版本.因为我使用的是MVC4,所以直接安装的是auto ...
- 如何在asp.net mvc 中使用Autofac 控制反转(Ioc)
前言 最近看了一些关于Ioc方面的开源项目,里面的类跳来转去,看的迷迷糊糊的.项目里根本不需要这么“复杂的”设计,只需简单完成Ico,达到解耦的目的,并且能高效的完成项目.于是参考autofac的官网 ...
- ADO.NET .net core2.0添加json文件并转化成类注入控制器使用 简单了解 iTextSharp实现HTML to PDF ASP.NET MVC 中 Autofac依赖注入DI 控制反转IOC 了解一下 C# AutoMapper 了解一下
ADO.NET 一.ADO.NET概要 ADO.NET是.NET框架中的重要组件,主要用于完成C#应用程序访问数据库 二.ADO.NET的组成 ①System.Data → DataTable, ...
- ASP.NET MVC IOC 之AutoFac
ASP.NET MVC IOC 之AutoFac攻略 一.为什么使用AutoFac? 之前介绍了Unity和Ninject两个IOC容器,但是发现园子里用AutoFac的貌似更为普遍,于是捯饬了两天, ...
- 2.ASP.NET MVC 中使用Crystal Report水晶报表
上一篇,介绍了怎么导出Excel文件,这篇文章介绍在ASP.NET MVC中使用水晶报表. 项目源码下载:https://github.com/caofangsheng93/CrystalReport ...
- 关于 ASP.NET MVC 中的视图生成
在 ASP.NET MVC 中,我们将前端的呈现划分为三个独立的部分来实现,Controller 用来控制用户的操作,View 用来控制呈现的内容,Model 用来表示处理的数据. 从控制器到视图 通 ...
- 在Asp.Net MVC 中配置 Serilog
Serilog 是一种非常简便记录log 的处理方式,使用Serilog可以生成本地的text文件, 也可以通过 Seq 来在Web界面中查看具体的log内容. 接下来就简单的介绍一下在Asp.Net ...
随机推荐
- mysql如何查找某字段所在表
如果是5.0以上的,以root用户连接,可以看到一个叫information_schema的表, 然后只要:use information_schema; select `TABLE_NAME`fro ...
- 网站的PV UV IP---网站常见软件性能
IP,衡量不同时间段的上网人数.00:00-24:00内相同的地址被计算一次.例:日300W IP,至少300W人访问PV,衡量页面受欢迎程度.每刷新一次,被记录一次(刷pv),网站被访问的页面的数量 ...
- [svc]mousedos网络批量部署xp
小时候对这个东西很好奇,不知道什么原理.一直觉得很好玩.现在研究了下,总结如下 软件的操作步骤很讲究,稍微不慎,则就需要重新来过 知识点: 1,掌握诺顿ghost分区为gh文件 2,学会清理至一个干净 ...
- error: expected expression before 'struct'
错误原因: 使用了offsetof函数,却没有包含头文件<stddef.h> 解决办法: 包含<stddef.h>
- MySQL通过视图(或临时表)实现动态SQL(游标)
>参考de优秀文章 写MySQL存储过程实现动态执行SQL Dynamic cursor in stored procedure MySQL通过视图(或临时表)实现动态SQL(游标). 因在实现 ...
- MFC图形编辑器
前言 vs2015竟然可以完美打开工程,哈哈可以直接生成类图了.由于内容较多,所以根据内容的重要性会安排详略. https://github.com/bajdcc/GraphEditor/releas ...
- js photoswipe 相册使用 移动pc端均可
http://photoswipe.com/ 官网 这里使用的是最新 4.1.1版本 http://photoswipe.com/documentation/getting-started.html ...
- 基于jplayer实现歌词同步的JS音乐播放器效果
分享一款基于jplayer实现歌词同步的JS音乐播放器效果.这是一款基于jQuery实现的音乐播放器功能代码.效果图如下: 在线预览 源码下载 实现的代码. html代码: <textare ...
- html5和css3打造一款创意404页面
之前和网友分享一款HTML5可爱的404页面动画 很逗的机器人.今天要爱编程小编要再给大家带来一款html5和css3打造的创意404页面.一起看下效果图吧: 在线预览 源码下载 实现的代码. h ...
- Object中有哪些方法?
有一种遗憾就是,每天都见到你,但是却不关注你!等到面试的时候才后悔莫及. Object类中有9大public方法: equals:判断两个对象"相等" hashCode:获取对象的 ...