ow
This commit is contained in:
commit
f05d2d215f
678 files changed
+73865
No files matched your search
@@ -0,0 +1,34 @@
|
||||
using CloudBuilder.Core.DependencyInjection.Request;
|
||||
using CloudBuilder.Core.Policy;
|
||||
using DocumentFormat.OpenXml.InkML;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.DependencyInjection.Form
|
||||
{
|
||||
public class ApplicationServiceContext
|
||||
{
|
||||
public static IServiceProvider ServiceProvider = null!;
|
||||
public static IContext Context = null!;
|
||||
public static IConfiguration Configuration;
|
||||
public static ILocaleMessageManager localeMessageManager = null!;
|
||||
public static ISecurityMasterManager securityMasterManager = null!;
|
||||
public ApplicationServiceContext(IServiceProvider serviceProvider, IContext context, IConfiguration configuration)
|
||||
{
|
||||
ServiceProvider = serviceProvider;
|
||||
Context = context;
|
||||
Context.DefaultVersion = configuration.GetValue<string>("CloudBuilder:DefaultVersion")!;
|
||||
Context.DefaultCopyright = configuration.GetValue<string>("CloudBuilder:DefaultCopyright")!;
|
||||
Context.DefaultTitle = configuration.GetValue<string>("CloudBuilder:DefaultTitle")!;
|
||||
|
||||
Configuration = configuration;
|
||||
localeMessageManager = ServiceProvider.GetService<ILocaleMessageManager>()!;
|
||||
securityMasterManager = ServiceProvider.GetService<ISecurityMasterManager>()!;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using CloudBuilder.Core.Application.Builders;
|
||||
using CloudBuilder.Core.Application.Packs;
|
||||
using CloudBuilder.Core.DatabaseAccessor;
|
||||
using CloudBuilder.Core.DatabaseAccessor.Entity;
|
||||
using CloudBuilder.Core.DependencyInjection.EFCore;
|
||||
using CloudBuilder.Core.DependencyInjection.Request;
|
||||
using CloudBuilder.Core.Extensions;
|
||||
using CloudBuilder.Core.Service;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.DependencyInjection.Form
|
||||
{
|
||||
[PackLevel(40)]
|
||||
public class FormPack : CloudBuilderPack
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 模块级别
|
||||
/// </summary>
|
||||
public override PackLevel Level => PackLevel.Business;
|
||||
|
||||
/// <summary>
|
||||
/// 获取 模块启动顺序,模块启动的顺序先按级别启动,级别内部再按此顺序启动
|
||||
/// </summary>
|
||||
public override int Order => 2;
|
||||
|
||||
/// <summary>
|
||||
/// 将窗体和用户控件添加到依赖注入服务容器中
|
||||
/// </summary>
|
||||
/// <param name="services">依赖注入服务容器</param>
|
||||
/// <returns></returns>
|
||||
public override IServiceCollection AddServices(IServiceCollection services, CloudBuilderBuilder builder)
|
||||
{
|
||||
//注入窗体
|
||||
var baseType = typeof(IForm);
|
||||
|
||||
var allAssemblies = CloudBuilderBuilder.GetAssemblies();
|
||||
|
||||
var types = allAssemblies
|
||||
.SelectMany(a => a.DefinedTypes)
|
||||
.Select(type => type.AsType())
|
||||
.Where(type => type != baseType && type.BaseType?.Name != "AbstractPage" && type.HasImplementedRawGeneric(baseType))
|
||||
.Where(x => x.IsClass).ToList();
|
||||
|
||||
|
||||
foreach (var implementType in types)
|
||||
{
|
||||
services.TryAddKeyedScoped(implementType, implementType.Name);
|
||||
}
|
||||
|
||||
//注入Page
|
||||
baseType = typeof(IForm);
|
||||
|
||||
allAssemblies = CloudBuilderBuilder.GetAssemblies();
|
||||
|
||||
types = allAssemblies
|
||||
.SelectMany(a => a.DefinedTypes)
|
||||
.Select(type => type.AsType())
|
||||
.Where(type => type != baseType && type.BaseType?.Name == "AbstractPage" && type.HasImplementedRawGeneric(baseType))
|
||||
.Where(x => x.IsClass).ToList();
|
||||
|
||||
|
||||
foreach (var implementType in types)
|
||||
{
|
||||
//主界面窗口及弹出的窗口,要使用Transient注入,每次打开都要创建新的实例
|
||||
//注意要清空之前的自定义属性。BindingContextAttributeProvider
|
||||
services.TryAddKeyedTransient(implementType.BaseType, implementType.Name, implementType);
|
||||
//services.TryAddKeyedScoped(implementType.BaseType, implementType.Name, implementType);
|
||||
}
|
||||
|
||||
//注入用户控件
|
||||
baseType = typeof(IUserControl);
|
||||
types = allAssemblies
|
||||
.SelectMany(a => a.DefinedTypes)
|
||||
.Select(type => type.AsType())
|
||||
.Where(type => type != baseType && type.HasImplementedRawGeneric(baseType))
|
||||
.Where(x => x.IsClass).ToList();
|
||||
|
||||
foreach (var implementType in types)
|
||||
{
|
||||
services.TryAddKeyedScoped(implementType, implementType.Name);
|
||||
}
|
||||
|
||||
//services.TryAddSingleton<ApplicationServiceContext>();
|
||||
services.TryAddScoped<ApplicationServiceContext>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.DependencyInjection.Form
|
||||
{
|
||||
public interface IForm
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CloudBuilder.Core.DependencyInjection.Form
|
||||
{
|
||||
public interface IUserControl
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user