Migration from Prism 7 to Prism 8

Viewed 85

I'm trying to upgrade from Prism 7.1.0.431 to 8.1.97 and I'm having several problems.

I think my biggest problem comes from replacing the "CommonServiceLocator.ServiceLocator.Current" with "Prism.Ioc.ContainerLocator.Container." (I know this is an anti-pattern,... but that's not the point)

I don't know how to replace : ServiceLocator.Current.GetAllInstances<>()

For example in this line of code where I get all the rights available in the application (in modules) that should be assignable to users:

IEnumerable rights = ServiceLocator.Current.GetAllInstances<CheckNavigationRights>().SelectMany(c => c.Rights).Distinct();

How can I do the same thing with Prism 8?

I use Unity.

Thank you very much for your help.

1 Answers

If you don't like Prism's container abstraction, you can use the container-specific static method GetContainer to get access to the underlying container:

using Prism.Unity;

IEnumerable rights = ContainerLocator.Container.GetContainer().GetAllInstances<CheckNavigationRights>().SelectMany(c => c.Rights).Distinct();

BTW: you could inject or resolve an IEnumerable<CheckNavigationRights> to get all the named registrations.

Related