diff --git a/.idea/.idea.SlnMesnac/.idea/.gitignore b/.idea/.idea.SlnMesnac/.idea/.gitignore new file mode 100644 index 0000000..c26363c --- /dev/null +++ b/.idea/.idea.SlnMesnac/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/projectSettingsUpdater.xml +/.idea.SlnMesnac.iml +/contentModel.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.SlnMesnac/.idea/encodings.xml b/.idea/.idea.SlnMesnac/.idea/encodings.xml new file mode 100644 index 0000000..bb16377 --- /dev/null +++ b/.idea/.idea.SlnMesnac/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.SlnMesnac/.idea/indexLayout.xml b/.idea/.idea.SlnMesnac/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.SlnMesnac/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.SlnMesnac/.idea/vcs.xml b/.idea/.idea.SlnMesnac/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/.idea.SlnMesnac/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SlnMesnac.Library/GRreader.dll b/SlnMesnac.Library/GRreader.dll new file mode 100644 index 0000000..70ee539 Binary files /dev/null and b/SlnMesnac.Library/GRreader.dll differ diff --git a/SlnMesnac.Repository/SqlsugarSetup.cs b/SlnMesnac.Repository/SqlsugarSetup.cs index 90a808e..779899f 100644 --- a/SlnMesnac.Repository/SqlsugarSetup.cs +++ b/SlnMesnac.Repository/SqlsugarSetup.cs @@ -45,17 +45,5 @@ namespace SlnMesnac.Repository return Db; }); } - - /// - /// 注册Repository、Service服务 - /// - /// - public static void AddServices(this IServiceCollection services) - { - //services.AddSingleton>(); - services.AddSingleton(typeof(Repository<>)); - services.AddSingleton(); - services.AddSingleton(); - } } } diff --git a/SlnMesnac.WPF/App.xaml.cs b/SlnMesnac.WPF/App.xaml.cs index 78c0506..00fe691 100644 --- a/SlnMesnac.WPF/App.xaml.cs +++ b/SlnMesnac.WPF/App.xaml.cs @@ -12,6 +12,11 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows; +using Autofac.Extensions.DependencyInjection; +using SlnMesnac.Common; +using SlnMesnac.Repository.service; +using SlnMesnac.Repository.service.Impl; +using SlnMesnac.Plc.Factory; namespace SlnMesnac.WPF { @@ -41,13 +46,13 @@ namespace SlnMesnac.WPF var host = CreateHostBuilder(e.Args).Build();//生成宿主。 ServiceProvider = host.Services; - await host.StartAsync(); + //var baseMaterialService = ServiceProvider.GetRequiredService(); var appConfig = host.Services.GetService(); var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; Log.Information($"系统初始化完成,日志存放路径:{appConfig.logPath}"); - + await host.StartAsync(); } /// @@ -58,6 +63,7 @@ namespace SlnMesnac.WPF public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .UseSerilog() + .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj index 38a951d..ba18e65 100644 --- a/SlnMesnac.WPF/SlnMesnac.WPF.csproj +++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj @@ -37,6 +37,7 @@ + diff --git a/SlnMesnac.WPF/Startup.cs b/SlnMesnac.WPF/Startup.cs index 29c207e..e11cc97 100644 --- a/SlnMesnac.WPF/Startup.cs +++ b/SlnMesnac.WPF/Startup.cs @@ -11,8 +11,10 @@ using SlnMesnac.Serilog; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; +using Autofac; using Microsoft.Extensions.Configuration; using SlnMesnac.Mqtt; using SlnMesnac.Rfid; @@ -48,9 +50,6 @@ namespace SlnMesnac.WPF //注册ORM services.AddSqlSugarSetup(); - //注册Service - services.AddServices(); - //注册Quartz //services.AddQuartzSetUp(); @@ -66,6 +65,30 @@ namespace SlnMesnac.WPF //注册RFID services.AddRfidSetup(); } + + public void ConfigureContainer(ContainerBuilder builder) + { + builder.RegisterGeneric(typeof(Repository<>)).As(typeof(Repository<>)); + RegisterImplementations(builder, typeof(Repository<>).Assembly); + } + + private static void RegisterImplementations(ContainerBuilder builder, Assembly assembly) + { + //自动注入仓储层的接口实现类 + var types = assembly.GetTypes() + .Where(t => t.IsClass && !t.IsAbstract && !t.IsGenericType) + .ToList(); + + foreach (var type in types) + { + var interfaces = type.GetInterfaces(); + + foreach (var @interface in interfaces) + { + builder.RegisterType(type).As(@interface); + } + } + } /// /// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/SlnMesnac/Startup.cs b/SlnMesnac/Startup.cs index 7dccfe0..fad02a2 100644 --- a/SlnMesnac/Startup.cs +++ b/SlnMesnac/Startup.cs @@ -79,7 +79,7 @@ namespace SlnMesnac services.AddSqlSugarSetup(); //注册服务 - services.AddServices(); + //services.AddServices(); //注册任务调度 services.AddQuartzSetUp();