基于AspNet Core2.0(测试版) 开发框架,包含简单的个人博客Demo
大家好,最近离职了,利用闲暇时间就捣鼓了一个基于AspNet Core开发框架,分享出来希望能给AspNet Core学者带来一些帮助,同时也能跟大家一起学习。当然了,由于我的个人技术及经验的有限,框架还是有很多Bug或不足之处,希望各位大神或园友指出,我会继续完善的,可以通过这些方式联系到我qq:891022171、邮箱:lishuyiba@126.com
以下仅代表个人观点,与本人所在公司无关。
使用到的技术:AspNet Core 2.0 + EF +Auofac+ SqlServer2012 + Bootstrap + Layer + ace admin
根据的理解,目前我知道有三种比较好依赖注入管理的方式
1、 第一种、定义依赖注入接口,只要实现了该接口的都自动注入到IOC容器。
2、 第二种、定义特定的后缀,只要符合该特定后缀都自动注入到IOC容器。
3、 第三种、定义特性类,查找标识有该特性的类并注入到IOC容器。
我的项目使用了第一种,基本思路如下
程序启动时查找bin下所有的DLL并利用反射查找实现了IDependencyAutofacRegistrar接口的类注入到容器,实现解耦。
说明:
1、由于目前Core 2.0属于预览版,启动web项目时不能打开网页,可能跟版本有关,等正式版发布后,我再重新发布看看。。。。
2、想要VS2017能编译通过,要修改环境变量,添加MSBuildSdksPath,并设置 Core2.0 SDK的路径,下面是我本机的配置。。。 Core2.0 SDK下载地址:https://download.microsoft.com/download/3/7/F/37F1CA21-E5EE-4309-9714-E914703ED05A/dotnet-dev-win-x64.2.0.0-preview1-005977.exe
######################下面先来看看效果图吧###################
说明:下面这些效果图我是用Core 1.0 开发的,还有很多API没有加入。本次分享的项目是用Core2.0开发的,主要是因为Core2.0加入了好多以前.Net4.6的API(查询API:https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly?view=netcore-2.0),用起来比较方便,但是网站页面不打开,数据是正常返回的,可能是预览版的问题(前面有提过),感兴趣需要页面的朋友可以 艾特 问我要。
看 data 数据返回:
先来看看前台效果图,只是简单的把输出显示出来,效果很丑,别笑哦~ 因为没时间找好看的模板~~~
再来看看后台效果图,主题选用: ace admin,列表显示用Bootstrap ,弹出层用Layer
项目的大体结构
lsyi. Web------------ web项目。
lsyi.Core ------------------框架的核心都封装在这。
lsyi.Data ----------------数据访问
lsyi. Autofac --------------------Autofac IOC容器
lsyi. Ninject ---------Ninject IOC容器
lsyi. Models --------------项目模型
lsyi. Services --------------服务
###############好了,下面给大家介绍框架封装的东西###################
首页
后台登录
后台首页
添加文章页面
由于时间原因,框架的介绍后面有空我再详细补上~~
项目地址在这里,很多同学反馈说没有界面,今天上传了一个新的。
############################################################
新:https://github.com/lishuyiba/Sys.Framework (有界面)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
CREATE DATABASE [Robot] GO USE [Robot] GO /****** Object: Table [dbo].[T_Robot_Log] Script Date: 2017/12/12 17:23:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[T_Robot_Log]( [F_Id] [int] IDENTITY(1,1) NOT NULL, [F_LogType] [int] NULL, [F_LogConent] [nvarchar](max) NULL, [F_CreateTime] [datetime] NULL, PRIMARY KEY CLUSTERED ( [F_Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[T_Robot_Meal] Script Date: 2017/12/12 17:23:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[T_Robot_Meal]( [F_Id] [int] IDENTITY(1,1) NOT NULL, [F_MealName] [nvarchar](200) NULL, [F_MealCode] [nvarchar](200) NULL, [F_Status] [int] NULL, [F_CreateTime] [datetime] NULL, CONSTRAINT [PK__T_Robot___2C6EC723E6ED0CFD] PRIMARY KEY CLUSTERED ( [F_Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[T_Robot_Role] Script Date: 2017/12/12 17:23:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[T_Robot_Role]( [F_Id] [int] IDENTITY(1,1) NOT NULL, [F_RoleName] [nvarchar](40) NULL, [F_CreateTime] [datetime] NULL, PRIMARY KEY CLUSTERED ( [F_Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[T_Robot_Status] Script Date: 2017/12/12 17:23:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[T_Robot_Status]( [F_Id] [int] IDENTITY(1,1) NOT NULL, [F_Type] [int] NULL, [F_Status] [int] NULL, PRIMARY KEY CLUSTERED ( [F_Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[T_Robot_Task] Script Date: 2017/12/12 17:23:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[T_Robot_Task]( [F_Id] [int] IDENTITY(1,1) NOT NULL, [F_TaskName] [nvarchar](300) NULL, [F_TaskParam] [nvarchar](max) NULL, [F_CronExpressionString] [nvarchar](200) NULL, [F_AssemblyName] [nvarchar](150) NULL, [F_ClassName] [nvarchar](150) NULL, [F_Status] [int] NULL, [F_IsDelete] [int] NULL, [F_CreatedTime] [datetime] NULL, [F_ModifyTime] [datetime] NULL, [F_RecentRunTime] [datetime] NULL, [F_NextFireTime] [datetime] NULL, [F_CronRemark] [nvarchar](300) NULL, [F_Remark] [nvarchar](1000) NULL, PRIMARY KEY CLUSTERED ( [F_Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[T_Robot_Transition] Script Date: 2017/12/12 17:23:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[T_Robot_Transition]( [F_Id] [int] IDENTITY(1,1) NOT NULL, [F_BusinessCode] [nvarchar](200) NULL, [F_NetOrder] [nvarchar](200) NULL, [F_AccessNumber] [nvarchar](200) NULL, [F_Status] [int] NULL, [F_CreateTime] [datetime] NULL, [F_Remark] [nvarchar](500) NULL, CONSTRAINT [PK__T_Robot___2C6EC72325890140] PRIMARY KEY CLUSTERED ( [F_Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[T_Robot_User] Script Date: 2017/12/12 17:23:28 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[T_Robot_User]( [F_Id] [int] IDENTITY(1,1) NOT NULL, [F_RoleId] [int] NULL, [F_Account] [nvarchar](40) NULL, [F_Password] [nvarchar](40) NULL, [F_CreateTime] [datetime] NULL, [F_IsDelete] [int] NULL, CONSTRAINT [PK__T_Robot___2C6EC72332F0437C] PRIMARY KEY CLUSTERED ( [F_Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO
############################################################
旧:https://github.com/lishuyiba/lsyiFramework (无界面)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
USE [dbCore] GO /****** Object: Table [dbo].[Article] Script Date: 2018/1/6 23:16:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Article]( [Id] [int] IDENTITY(1,1) NOT NULL, [AuthorId] [int] NOT NULL, [CategoryId] [int] NOT NULL, [Content] [nvarchar](max) NULL, [CreateTime] [datetime2](7) NOT NULL, [DelFlag] [int] NOT NULL, [LastEditTime] [datetime2](7) NOT NULL, [Status] [int] NOT NULL, [Title] [nvarchar](max) NULL, [ViewCount] [int] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[Category] Script Date: 2018/1/6 23:16:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Category]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](max) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[Role] Script Date: 2018/1/6 23:16:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Role]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](max) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[SystemLog] Script Date: 2018/1/6 23:16:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[SystemLog]( [Id] [int] IDENTITY(1,1) NOT NULL, [Date] [datetime2](7) NOT NULL, [Operate] [nvarchar](max) NULL, [UserName] [nvarchar](max) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[Tag] Script Date: 2018/1/6 23:16:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Tag]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](max) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[Users] Script Date: 2018/1/6 23:16:38 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Users]( [Id] [int] IDENTITY(1,1) NOT NULL, [Account] [nvarchar](max) NULL, [Password] [nvarchar](max) NULL, [CreateTime] [datetime2](7) NOT NULL, [LastEditTime] [datetime2](7) NOT NULL, [DelFlag] [int] NOT NULL, [RoleID] [int] NOT NULL, [Status] [int] NOT NULL, CONSTRAINT [PK_T_CMS_CONTENTTAG] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO
############################################################
参考资料:
http://www.cnblogs.com/flyfish2012/p/3779810.html
http://docs.autofac.org/en/latest/integration/webapi.html
http://www.cnblogs.com/gamehiboy/p/5176618.html
https://docs.microsoft.com/en-us/ef/core/index
http://docs.autofac.org/en/latest/integration/webapi.html