1
\$\begingroup\$

sorry for this type of question, I am wondering if are there any good code practice to use in order to isolate IOCs on my App.cs RegisterTypes since it's getting bigger. Like isolating the registration of navigation and abstractions. E.g.

protected override void RegisterTypes()
{
     Container.RegisterTypeForNavigation<NavigationPage>();
     Container.RegisterTypeForNavigation<NavigationPage1>();
     Container.RegisterTypeForNavigation<NavigationPage2>();
     Container.RegisterTypeForNavigation<NavigationPage3>();
     Container.RegisterTypeForNavigation<NavigationPage_1_1>();
     Container.RegisterTypeForNavigation<NavigationPage_1_2>();
     Container.RegisterTypeForNavigation<NavigationPage_1_3>();
}

Where NavigationPage to NavigationPage3 and NavigationPage_1_1 to NavigationPage_1_3 will be both isolated.

Thanks.

\$\endgroup\$
1
  • \$\begingroup\$ It depends on IoC container. Some containers have decent support for modular registration. I mostly work with Castle.Windsor and it has a special WindsorInstaller class to encapsulate and reuse registration logic. You can also consider registration by convention, where you register types that fit specific pattern (or have a certain attribute) automatically using reflection. \$\endgroup\$
    – Nikita B
    Apr 4, 2018 at 8:30

1 Answer 1

1
\$\begingroup\$

If I'm reading this correctly you want to have different way to group pages together for registration. Besides making a new method for each group there isn't a good way by hand to do this. At the end all your pages are still registered in the same container. You could create child containers for each group but then need to make extension methods for navigation that knows about child containers. Yuck and over-kill.

If your main issue is that the registration method is getting too big then just look at switching it around. We use MEF to load a catalog and have all our views have a RegisterView attribute than use the MEF catalog to build the registrations for the views in Prism. We use MEF for other things in our application and I think it would be over kill to use MEF just for registration. Another way instead of MEF is to just use reflection and to wire it up yourself. I was going to write the code how to do that but did a quick Google search and low and behold Stack Overflow already had an answer

https://stackoverflow.com/a/37039538

They just looking for Pages but if you wanted you could make an attribute and look for that if you needed but Page object is probably what you need.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks. One thing I've also looked into is modularity, apparently this helped (idk the reason why) also helped to fixed the bug when navigating on a certain page where I needed to make it an absolute before navigating through it. And I think prism is going away from Bootstrapper, that is why PrismApplication was created (correct me if I am wrong). \$\endgroup\$
    – Swift_Talt
    Dec 4, 2017 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.