[英]Move container registrations to a new assembly with Prism.Unity.Forms
我目前在 Xamarin.Forms 项目中使用 Prism 和 Unity。
我在用着
protected override void RegisterTypes(IContainerRegistry containerRegistry) {}
在 App.xaml.cs 中注册我的课程,但是随着我的项目的增长,这种方法/使用次数等也会增加。
我考虑将一些注册卸载到它们各自的命名空间。 也就是说,如果我有一个用户命名空间,我可以有一个 class 像这样:
public sealed class UsersRegistry : IRegistry {
public UsersRegistry(IUnityContainer container)
{
container.RegisterType<IUserService, UserService>();
}
}
我首先使用程序集扫描来查找所有实现 IRegistry 的类,但是我对如何创建 class 并传入 Prism 使用的容器有一些简短的说明。
我正在尝试这样的事情:
var registries = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(type => typeof(IRegistry).IsAssignableFrom(type) && !type.IsInterface);
foreach (var type in registries) {
var instance = Activator.CreateInstance(type, <get unity container here>);
}
但我不确定这是正确的方向。
此外,它不必是这种特殊的方式。 我在这里的主要目标是将导航注册和我的各种类型分解为一个更易于管理的系统。
任何帮助,将不胜感激。
Prism 以模块的形式提供此功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.