返回提交历史
Modified
XFEExtension.NetCore.WinUIHelper.TestApp/App.xaml.cs
+5
-0
Modified
XFEExtension.NetCore.WinUIHelper/Utilities/ServiceManager.cs
+3
-11
Modified
XFEExtension.NetCore.WinUIHelper/XFEExtension.NetCore.WinUIHelper.csproj
+2
-1
XFEstudio/XFEExtension.NetCore.WinUIHelper
采用反射获取接口的实现类
733531a
代码差异
3 个文件
+10
-12
@@ -1,4 +1,6 @@
1
1
using Microsoft.UI.Xaml;
2
using XFEExtension.NetCore.WinUIHelper.Interface.Services;
3
using XFEExtension.NetCore.WinUIHelper.Utilities;
2
4
3
5
namespace XFEExtension.NetCore.WinUIHelper.TestApp
4
6
{
@@ -14,6 +16,9 @@ namespace XFEExtension.NetCore.WinUIHelper.TestApp
14
16
public App()
15
17
{
16
18
this.InitializeComponent();
19
var service = ServiceManager.GetService<ISelectorBarService>();
20
var service2 = ServiceManager.GetService<INavigationParameterService<string>>();
21
var service3 = ServiceManager.GetService<IMessageService>();
17
22
}
18
23
19
24
/// <summary>
@@ -11,16 +11,7 @@ public static class ServiceManager
11
11
private static readonly List<IGlobalService> globalServices = [];
12
12
private static readonly Dictionary<string, Func<object>> services = new()
13
13
{
14
{ nameof(IAutoNavigationService), () => new AutoNavigationService() },
15
{ nameof(IDialogService), () => new DialogService() },
16
{ nameof(IListViewService), () => new ListViewService() },
17
{ nameof(ILoadingService), () => new LoadingService() },
18
{ nameof(IMessageService), () => new MessageService() },
19
{ nameof(INavigationService), () => new AutoNavigationService() },
20
{ nameof(INavigationViewService), () => new NavigationViewService() },
21
{ nameof(IPageService), () => new PageService() },
22
{ nameof(ISettingService), () => new SettingService() },
23
{ nameof(IUserLoginService), () => new UserLoginService() }
14
{ nameof(INavigationService), () => new AutoNavigationService() }
24
15
};
25
16
/// <summary>
26
17
/// 注册全局服务
@@ -56,6 +47,7 @@ public static class ServiceManager
56
47
var typeName = typeof(T).Name;
57
48
if (services.TryGetValue(typeName, out var ctr))
58
49
return (T)ctr();
59
throw new NullReferenceException("无法找到指定服务的实现类");
50
else
51
return (T?)Activator.CreateInstance(type.Assembly.GetType($"XFEExtension.NetCore.WinUIHelper.Implements.Services.{type.Name![1..]}") ?? throw new NullReferenceException("无法找到指定服务的实现类")) ?? throw new NullReferenceException("无法找到指定服务的实现类");
60
52
}
61
53
}
@@ -9,7 +9,7 @@
9
9
<Nullable>enable</Nullable>
10
10
<GenerateDocumentationFile>True</GenerateDocumentationFile>
11
11
<Title>XFEExtension.NetCore.WinUIHelper</Title>
12
<Version>1.1.0</Version>
12
<Version>1.1.1</Version>
13
13
<Authors>XFEstudio</Authors>
14
14
<PackageIcon>logoIcon.png</PackageIcon>
15
15
<Description>WinUI的各种工具类,帮助开发者快速构建一个模块化的WinUI项目</Description>
@@ -17,6 +17,7 @@
17
17
<NeutralLanguage>zh-CN</NeutralLanguage>
18
18
<PackageReadmeFile>README.md</PackageReadmeFile>
19
19
<PackageReleaseNotes>
20
采用反射获取接口的实现类
20
21
</PackageReleaseNotes>
21
22
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
22
23
<PackageProjectUrl>https://github.com/XFEstudio/XFEExtension.NetCore.WinUIHelper</PackageProjectUrl>