JoreNoe 6.9.9.8

dotnet add package JoreNoe --version 6.9.9.8
NuGet\Install-Package JoreNoe -Version 6.9.9.8
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JoreNoe" Version="6.9.9.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JoreNoe --version 6.9.9.8
#r "nuget: JoreNoe, 6.9.9.8"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JoreNoe as a Cake Addin
#addin nuget:?package=JoreNoe&version=6.9.9.8

// Install JoreNoe as a Cake Tool
#tool nuget:?package=JoreNoe&version=6.9.9.8

JoreNoe

安装方法

Build NuGet Downloads
alternate text is missing from this package README image alternate text is missing from this package README image <a href="https://www.nuget.org/packages/JoreNoe/" rel="nofollow noreferrer"><img src="https://img.shields.io/nuget/dt/JoreNoe?label=Downloads" alt="NuGet Downloads"></a>
Install-Package JoreNoe -Version 6.9.9.4

文档目录

ORM使用
Redis使用
发送消息
帮助扩展方法
中间件使用

ORM使用说明

JoreNoe包目前支持数据库:Mysql , SqlServer

支持,ORM框架 Dapper,EFCore

<a name="OPT1-1"></a>

1.Dapper 使用

首先第一步引用
using JoreNoe.DB.Dapper
第二步进行注册

在您的应用程序启动时,将服务添加到依赖注入容器中。您可以在 Startup.cs 文件中的 ConfigureServices 方法中调用 AddJoreNoeDapper 方法来注册服务。

public void ConfigureServices(IServiceCollection services)
{
    services.AddJoreNoeDapper("your_connection_string_here", IDBType.SqlServer);
    // 或者
    // services.AddJoreNoeDapper("your_connection_string_here", IDBType.MySql);
}
第三步使用服务
public class YourService
{
    private readonly IRepository<test> TestRepository;

    public YourService(IRepository<test> TestRepository)
    {
        this.TestRepository = TestRepository;
    }

    public void YourMethod()
    {
        this.TestRepository.Add(new ...);
    }
}
属性获取
public class YourService
{
    private readonly IDatabaseService dataBaseService;

    public YourService(IDatabaseService dataBaseService)
    {
        this.dataBaseService = dataBaseService;
    }

    public IDbConnection GetConnection()
    {
        this.dataBaseService.GetConnection();
    }
    
    public string GetPropValue()
    {
        return this.dataBaseService.DataBaseSettings.connectionString; // 返回链接字符串
        return this.dataBaseService.DataBaseSettings.dbType; // 返回数据库类型
         return this.dataBaseService.DataBaseSettings.mulitInsertBatchcount; // 返回批量插入 一批次数量
        
    }
    
}
不使用注入方式
public class UserController
{
    var database = new Repository<test>(new DatabaseService("your_connection_string_here",默认Mysql,默认20万));
    database.add(new test{...});
}

<a name="OPT1-2"></a>

2.EntityFramework.Core使用

首先第一步引用

1.在仓储项目中创建

1.1 RepositoryModule.cs

1.2 IntegratedPlatformSupporRegister.cs  名字可随意 

2.创建上下文

2.1 IntegratedPlatformSupporDBContext.cs 名字随意 
第二步具体代码实现

1.1.RepositoryModule.cs 文件 具体代码实现

using Autofac;
using JoreNoe;
using JoreNoe.DB.EntityFrameWork.Core.SqlServer;
namespace IntegratedPlatformSuppor.Repository
{
    public class RepositoryModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            builder.RegisterType<IntegratedPlatformSupporRegister>().As<ICurrencyRegister>().InstancePerLifetimeScope();
            builder.RegisterGeneric(typeof(Repository<,>)).As(typeof(IRepository<,>));
            builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerLifetimeScope();
        }
    }
}

1.2.IntegratedPlatformSupporRegister.cs 文件具体代码实现

using JoreNoe;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;

namespace IntegratedPlatformSuppor.Repository
{
    public class IntegratedPlatformSupporRegister : ICurrencyRegister, IDisposable
    {
        private DbContext _dbContext;

        public IntegratedPlatformSupporRegister(IConfiguration Configuration)
        {
            this._dbContext = new IntegratedPlatformSupporDBContext { Configuration = Configuration };
        }

        public DbContext Dbcontext { get => this._dbContext; set { this._dbContext = value; } }

        public void Dispose()
        {
            this._dbContext.Dispose();
        }
    }
}

2.1.IntegratedPlatformSupporDBContext.cs 文件具体代码实现

using IntegratedPlatformSuppor.Domain.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;

namespace IntegratedPlatformSuppor.Repository
{
    public class IntegratedPlatformSupporDBContext : DbContext
    {
        public IntegratedPlatformSupporDBContext()
        {
            //this.Configuration = configuration;
            //如果要访问的数据库存在,则不做操作,如果不存在,会自动创建所有数据表和模式
            //Database.EnsureCreated();

        }

        /// <summary>
        /// 配置
        /// </summary>
        public IConfiguration Configuration { set; get; }

        /// <summary>
        /// 用户
        /// </summary>
        public DbSet<User> Users { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!string.IsNullOrEmpty(this.Configuration.GetConnectionString("DbConnect")))
                optionsBuilder.UseSqlServer(this.Configuration.GetConnectionString("DbConnect"));
            else
                optionsBuilder.UseSqlServer("Server=47.106.198.147;Database=IntegratedPlatformSuppor;Uid=sa;Password=JoreNoe123$%^");
            base.OnConfiguring(optionsBuilder);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Test>().HasQueryFilter(t => t.IsDelete == false);
            modelBuilder.Entity<User>().HasQueryFilter(t => t.IsDelete == false);
            modelBuilder.Entity<MeansCategory>().HasQueryFilter(d => !d.IsDelete); //.HasQueryFilter(t => t.IsDelete == false);
        }
    }
}

进行注册

1.使用AutoFac

在项目中创建Autofac.json 文件 写入配置如下  根据实际情况进行自行调整
{
  "modules": [
    { "type": "IntegratedPlatformSuppor.Repository.RepositoryModule,IntegratedPlatformSuppor.Repository" },
    { "type": "IntegratedPlatformSuppor.API.APIModule,IntegratedPlatformSuppor.API" },
    { "type": "IntegratedPlatformSuppor.DomainService.DomainServiceModule,IntegratedPlatformSuppor.DomainService" }
    //{ "type": "JoreNoe.Modules.JoreNoeModule,JoreNoe" }
  ]
}

2.WebApi 项目中 Program.cs 文件中写入

using Autofac.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System.IO;

namespace IntegratedPlatformSuppor.API
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
             Host.CreateDefaultBuilder(args)
             .UseServiceProviderFactory(new AutofacServiceProviderFactory())
             .ConfigureAppConfiguration((appConfiguration, builder) =>
             {
                 builder
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("Configs/Redis.json", optional: false, reloadOnChange: true)
               .AddJsonFile("Configs/Exceptionless.json", optional: false, reloadOnChange: true)
               .AddJsonFile("Configs/WeChatOpenConfig.json", optional: false, reloadOnChange: true)
               .AddEnvironmentVariables().Build();
             })
             .ConfigureWebHostDefaults(webBuilder =>
             {
                 webBuilder.UseStartup<Startup>();
                 webBuilder.UseUrls("http://*:5000");
             });
    }
}

3.StartUp.cs 中加入

      public void ConfigureContainer(ContainerBuilder builder)
      {
          var config = new ConfigurationBuilder();
          config.AddJsonFile("./Configs/Autofac.json");
          builder.RegisterModule(new ConfigurationModule(config.Build()));
      }

实战使用

public class testDomainService :BaseRepository ,ItestDomainService
{
    private readonly IRepository<Guid, Test> test;
    public testDomainService(
        IRepository<Guid, Test> test,
        IUnitOfWork Unit):base(Unit)
    {
        this.test = test;
    }

    public TestValue k()
    {
        var xss = this.test.Single(Guid.NewGuid());
        return null;
    }

}

<a name="OPT2"></a>

3.Redis 使用说明

如何使用

1.注入 JoreNoe Redis 中注册上下文

public void ConfigureServices(IServiceCollection services)
{
    services.AddJoreNoeRedis("your_connection_string_here", "InstanceName",DefaultDB=0);
}

2.如何使用Redis

using  JoreNoe.Cache.Redis;

public class RedisTest
{
    private readonly JoreNoe.Cache.Redis.IRedisManager ReadisManager;
    public RedisTest(JoreNoe.Cache.Redis.IRedisManager ReadisManager) {
        this.ReadisManager = ReadisManager;
    }

    public void test()
    {
        this.ReadisManager.Add("Test", "test", JoreNoe.Cache.Redis.ExpireModel.LongCache);

        Console.WriteLine(this.ReadisManager.Get("Test"));
    }
}
3.直接调用
JoreNoe.Cache.Redis.JoreNoeRedisBaseService RedisDataBase = new JoreNoe.Cache.Redis.JoreNoeRedisBaseService(new JoreNoe.Cache.Redis.SettingConfigs {
    ConnectionString= "localhost:6379,password=mima",
    DefaultDB=1,
    InstanceName="TestRedis"
});

JoreNoe.Cache.Redis.IRedisManager RedisManager = new JoreNoe.Cache.Redis.RedisManager(RedisDataBase);

RedisManager.Add("Test","test", JoreNoe.Cache.Redis.ExpireModel.LongCache);

Console.WriteLine(RedisManager.Get("Test"));

Console.ReadLine();

<a name="OPT3"></a>

发送消息

目前支持:email 发送

1.邮箱发送

如何使用

using JoreNoe.Message;

public class test{
    
    public void sendtest(){

        // 首先注册 
        var EmailHelper = new EmailMessageAPI(发送者,SMTP地址,SMTP端口,密码(个人是授权码),是否开启SSL认证);
        
        EmailHelper.Send(收件人,标题,主题内容,是否开启兼容HTML);
    }
}

<a name="OPT4"></a>

帮助扩展方法

支持:boolean,字典转SQL,映射,实体转字典

1.bool 扩展方法

using JoreNoe.Extend;

public class test{
    
    public void sendtest(){

         /// <summary>
 /// 可用枚举类型 默认 1
 /// 类型1:IsOrDeny 是 否
 /// 类型2:TrueOrFalse 真 假
 /// 类型3:OnOrOff 开 关 
 /// 类型4:EnableOrDisable 启用 关闭
 /// </summary>
        
        var booltest = false;
         var REsult = booltest.BooleanToString(AvailableType.IsOrDeny);
        // 输出 否
        
    }
}
2.映射(AutoMapper)
// 直接使用方式 
var config = new MapperConfiguration(cfg =>
{
    cfg.CreateMap<test, test1>();
    cfg.CreateMap<test1, test>();
});
var mapper = new Mapper(config);
JoreNoe.Extend.JoreNoeObjectToObjectExtension.UseJoreNoeObjectToOBject(mapper);
var test = new test() {
    name = "c",
    age=123
};
var test1 = new test1();
// 将 test 数据 给 test1
var ment = test.Map(test1);
Console.ReadLine();

// NET 使用方式
// StartUp 
 public partial class Startup
    {
        protected void AddAutoMapper(IServiceCollection services)
        {
            services.TryAddSingleton<MapperConfigurationExpression>();
            services.TryAddSingleton(serviceProvider =>
            {
                var mapperConfigurationExpression = serviceProvider.GetRequiredService<MapperConfigurationExpression>();
                var instance = new MapperConfiguration(mapperConfigurationExpression);
                
                instance.AssertConfigurationIsValid();
                return instance;
            });
            services.TryAddSingleton(serviceProvider =>
            {
                var mapperConfiguration = serviceProvider.GetRequiredService<MapperConfiguration>();
                return mapperConfiguration.CreateMapper();
            });
        }
        public void UseAutoMapper(IApplicationBuilder applicationBuilder)
        {
            var config = applicationBuilder.ApplicationServices.GetRequiredService<MapperConfigurationExpression>();
            
            //订单
            config.CreateMap<OrderModel, Order>(MemberList.None);
            config.CreateMap<Order, OrderValue>(MemberList.None);

            //config.CreateMap<User, UserInfo>().ForMember(d => d.names, option => option.MapFrom(d => d.name)).ReverseMap();
        }
     
     
     // Program
      public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
             Host.CreateDefaultBuilder(args)
             .UseServiceProviderFactory(new AutofacServiceProviderFactory())
             .ConfigureAppConfiguration((appConfiguration, builder) =>
             {
                 builder
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("Configs/Redis.json", optional: false, reloadOnChange: true)
               .AddJsonFile("Configs/Exceptionless.json", optional: false, reloadOnChange: true)
               .AddJsonFile("Configs/WeChatOpenConfig.json", optional: false, reloadOnChange: true)
               .AddEnvironmentVariables().Build();
             })
             .ConfigureWebHostDefaults(webBuilder =>
             {
                 webBuilder.UseStartup<Startup>();
                 webBuilder.UseUrls("http://*:5000");
             });
     
     
     // StartUp Configure 中  
     public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment() || env.IsProduction())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ZerroMovies.API v1"));
            }
            app.UseObjectToOBjectExtension();
        }

<a name="OPT5"></a>

中间件的使用

1.全局错误日志中间件
// 使用方式1 webapi 全局错误日志中间件  直接使用方式
app.UseJoreNoeGlobalErrorHandlingMiddleware(async (ex, context) =>
{
    // 返回错误信息 // 处理自己的数据
    await Console.Out.WriteLineAsync(ex.Message);
});


// 使用方式2 注入 自定义类继承使用方式
builder.Services.AddJoreNoeGlobalErrorHandlingMiddleware<TestErrorMiddleWare>();
app.UseJoreNoeGlobalErrorHandlingMiddleware();
// 使用案例
using JoreNoe.Middleware;

namespace TestNET6Project
{
    public class TestErrorMiddleWare : IJoreNoeGlobalErrorHandling
    {
        public async Task GlobalErrorHandling(Exception Ex)
        {
            await Console.Out.WriteLineAsync(JoreNoeRequestCommonTools.FormatError(Ex));
        }
    }
}

2.全局运行日志中间件
// webapi 全局运行日志中间件  直接使用方式
app.UseJoreNoeRequestLoggingMiddleware(info => {
    Console.WriteLine("方法"+info.Method);
    Console.WriteLine("路径" + info.Path);
    Console.WriteLine("开始时间" + info.StartTime);
    Console.WriteLine("总时长" + info.Duration);
    Console.WriteLine("Get请求参数" + info.QueryString);
    Console.WriteLine("BODY请求参数" + info.RequestBody);
    Console.WriteLine("完整路径" + info.FullPathUrl);
    Console.WriteLine("Headers" + info.Headers);
});

// 注入 自定义类继承使用方式
builder.Services.AddJoreNoeRequestLoggingMiddleware<TestMiddleWare>();
app.UseJoreNoeRequestLoggingMiddleware();
// 使用案例
using JoreNoe.Middleware;

namespace TestNET6Project
{
    public class TestMiddleWare : IJorenoeRuningRequestLogging
    {
        public async Task RunningRequestLogging(JorenoeRuningRequestLoggingModel info)
        {
            Console.WriteLine("方法" + info.Method);
            Console.WriteLine("路径" + info.Path);
            Console.WriteLine("开始时间" + info.StartTime);
            Console.WriteLine("总时长" + info.Duration);
            Console.WriteLine("Get请求参数" + info.QueryString);
            Console.WriteLine("BODY请求参数" + info.RequestBody);
            Console.WriteLine("完整路径" + info.FullPathUrl);
            Console.WriteLine("Headers" + info.Headers);
        }
    }
}

Jorenoe Thanks use this package !!!

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
6.9.9.8 160 4/24/2024
6.9.9.7 74 4/24/2024
6.9.9.6 78 4/23/2024
6.9.9.5 74 4/23/2024
6.9.9.4 69 4/18/2024
6.9.9.3 72 4/16/2024
6.9.9.2 71 4/12/2024
6.9.9.1 75 4/11/2024
6.9.9 94 4/1/2024
6.9.7 82 4/1/2024
6.9.6 81 3/30/2024
6.7.7 165 12/28/2023
6.7.6 99 12/28/2023
6.7.5 159 11/3/2023
6.7.4 117 10/26/2023
6.7.3 106 10/26/2023
6.7.2 96 10/25/2023
6.7.1 111 10/25/2023
6.7.0 209 4/9/2023
6.6.9 228 4/5/2023
6.6.8 227 3/11/2023
6.5.8 521 7/30/2022
6.5.7 482 7/30/2022
6.5.6 455 7/29/2022
6.5.5 478 6/30/2022
6.5.4 478 6/28/2022
6.5.3 498 6/28/2022
6.5.2 474 6/28/2022
6.5.1 569 6/28/2022
6.5.0 500 6/27/2022
6.4.9 503 6/18/2022
6.4.8 470 6/17/2022
6.4.7 457 6/17/2022
6.4.6 490 6/17/2022
6.3.6 482 6/17/2022
6.3.4 483 6/17/2022
6.3.3 476 6/17/2022
6.3.2 463 6/17/2022
6.3.0 468 6/9/2022
6.2.0 519 6/8/2022
6.1.9 482 6/8/2022
6.1.8 478 6/7/2022
6.1.7 659 5/12/2022
6.1.6 514 5/12/2022
6.1.5 529 5/10/2022
6.1.4 519 5/10/2022
6.1.3 546 5/9/2022
6.1.2 514 5/9/2022
6.1.1 541 4/30/2022
6.1.0 527 4/30/2022
6.0.9 554 4/30/2022
6.0.8 524 4/30/2022
6.0.7 519 4/28/2022
6.0.6 539 4/28/2022
6.0.5 513 4/27/2022
6.0.4 513 4/27/2022
6.0.3 394 4/17/2022
6.0.2 399 4/17/2022
6.0.1 400 4/16/2022
6.0.0 405 4/16/2022
5.1.8 436 4/16/2022
5.1.7 402 4/16/2022
5.1.6 396 4/16/2022
5.1.5 407 4/16/2022
5.1.4 391 4/16/2022
5.1.3 400 4/16/2022
5.1.2 426 4/13/2022
5.1.1 311 10/22/2021
5.1.0 339 10/11/2021
5.0.9 283 9/23/2021
5.0.8 335 9/23/2021
5.0.7 374 9/23/2021
5.0.6 291 9/16/2021
5.0.5 322 9/15/2021
5.0.4 372 9/15/2021
5.0.3 263 9/15/2021
5.0.1 305 9/7/2021
5.0.0 267 9/3/2021
4.1.7 291 8/31/2021
4.1.6 369 8/31/2021
4.1.5 285 8/31/2021
4.1.4 281 8/31/2021
4.1.3 282 8/31/2021
4.1.2 285 8/31/2021
4.1.1 261 8/31/2021
1.0.5 312 8/18/2021
1.0.3 328 8/18/2021
1.0.2 318 8/18/2021