2022年2月27日

IOC框架-AutoFac

Extensions层通过Nuget安装Autofac.Extras.DynamicProxy,Autofac.Extensions.DependencyInjection,

添加项目引用

新建ServiceExtensions文件夹,完成AutoFacModuleRegister

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class AutofacModuleRegister : Autofac.Module
 {
     protected override void Load(ContainerBuilder builder)
     {
         //builder.RegisterType<ArticleService>().As<IArticleService>();
 
         var cacheType = new List<Type>();
 
         if (AppSettings.app(new string[] { "Appsettings", "LogAOP", "Enabled" }).ObjToBool())
         {
             builder.RegisterType<BlogLogAop>();
             cacheType.Add(typeof(BlogLogAop));
         }
 
         if (AppSettings.app(new string[] { "Appsettings", "MemoryCachingAOP", "Enabled" }).ObjToBool())
         {
             builder.RegisterType<BlogCacheAop>();
             cacheType.Add(typeof(BlogCacheAop));
         }
 
          
 
 
         var assemblyServices = Assembly.Load("SwiftCode.BBS.Services");
         builder.RegisterAssemblyTypes(assemblyServices).AsImplementedInterfaces().EnableInterfaceInterceptors().InterceptedBy(cacheType.ToArray());
 
         var assemblyRepositories = Assembly.Load("SwiftCode.BBS.Repositories");
         builder.RegisterAssemblyTypes(assemblyRepositories).AsImplementedInterfaces().InstancePerLifetimeScope();
 
 
 
     }
 }

test在Program.cs中新增

1
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());

注册服务

1
2
3
4
builder.Host.ConfigureContainer<ContainerBuilder>(builder =>
{
    builder.RegisterModule<AutofacModuleRegister>();
});

  

posted @ 2022-02-27 16:34 血气方刚 阅读(298) 评论(0) 推荐(0) 编辑

AutoMapper

摘要: Auto是一种实体转换关系的模型,是一个.Net的对象映射工具 引入AutoMapper的相关包 在Extensions层中引入Nuget包,AutoMapper和Automapper.Extensions.Microsoft.DependencyInjection 添加映射文件 public cl 阅读全文

posted @ 2022-02-27 16:19 血气方刚 阅读(252) 评论(0) 推荐(0) 编辑

Entity Framework Core 数据库访问与仓储模式

摘要: 创建实体模型与数据库 创建实体模型 public class Article { public int Id { get; set; } public string Submitter { get; set; } public string Title { get; set; } public st 阅读全文

posted @ 2022-02-27 16:01 血气方刚 阅读(134) 评论(0) 推荐(0) 编辑

授权与认证

摘要: 使用JWT进行授权验证的步骤 服务注册与参数配置 新建一个.Net6类库,在类库下新建Helper文件夹,并创建Appsetting类,该类用于帮助读取Appsetting.json中的系统配置参数 通过Nuget安装Microsoft.Extensions.Configuration;Micros 阅读全文

posted @ 2022-02-27 14:52 血气方刚 阅读(73) 评论(0) 推荐(0) 编辑

JWTHelper

摘要: public class JWTHelper { public static string IssueJwt(TokenModelJwt tokenModel) { string iss = AppSettings.app(new string[] { "Audience", "Issuer" }) 阅读全文

posted @ 2022-02-27 09:59 血气方刚 阅读(515) 评论(0) 推荐(0) 编辑

.Net 6 读取Appsetting的值的复制类

摘要: public class AppSettings { static IConfiguration Configuration { get; set; } static string ContentPath { get; set; } public AppSettings() { string pat 阅读全文

posted @ 2022-02-27 09:58 血气方刚 阅读(958) 评论(0) 推荐(0) 编辑

2020年8月2日

Git 添加项目到服务器

摘要: 1.创建本地项目 2.进入本地项目文件夹,右键选择"Git bash here" 3.创建本地仓库 在Git客户端,输入:Git init 初始化本地仓库 输入Git add . 将文件添加到本地仓库 输入Git comment -m '注释' 把文件提交到本地仓库 4.将本地仓库关联服务器远程仓库 阅读全文

posted @ 2020-08-02 20:17 血气方刚 阅读(239) 评论(0) 推荐(0) 编辑

Vue+Element UI 开发

摘要: 一、安装npm nodejs时,会自动安装npm,nodejs官网下载最新的安装包,选择安装目录,安装完成后,打开dos命令,输入node -v命令,会显示安装的nodejs版本,表明安装成功。 在dos命令窗口输入npm -v命令,会显示安装的npm版本。 安装vscode 下载地址:https: 阅读全文

posted @ 2020-08-02 09:14 血气方刚 阅读(305) 评论(0) 推荐(0) 编辑

2019年5月21日

.net try catch

摘要: 如果 try 中语句发生异常,catch捕获后,catch后面的语句会执行。 阅读全文

posted @ 2019-05-21 07:22 血气方刚 阅读(434) 评论(0) 推荐(0) 编辑

2019年4月17日

.net as 运算符

摘要: as 运算符类似于类型转换,不同的是,转换失败时返回NULL,而不是抛出异常。 阅读全文

posted @ 2019-04-17 07:36 血气方刚 阅读(504) 评论(0) 推荐(0) 编辑

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示