I'm currently using Prism with Unity in a Xamarin.Forms project.
I'm using
protected override void RegisterTypes(IContainerRegistry containerRegistry) {}
to register my classes in App.xaml.cs, but as my project grows, so does this method / numbers of usings, etc.
I thought about offloading some of the registrations to their respective namespaces. That is, if I have a namespace for Users, I can have a class like this:
public sealed class UsersRegistry : IRegistry {
public UsersRegistry(IUnityContainer container)
{
container.RegisterType<IUserService, UserService>();
}
}
I started by using assembly scanning to find all classes that implement IRegistry, but I'm coming up a little short on how to create the class and pass in the container used by Prism.
I was attempting something like this:
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>);
}
But I'm not certain this is the correct direction.
Also, it doesn't have to be this particular way. My main goal here is to break out the registrations for navigation and my various types into a more manageable system.
Any help would be appreciated.