In my opinion using the ServiceLocator isn't a bad practice. However, note that if you will unit test your component, you will have an additional dependency to mock (i.e. the service locator), which would add unnecessary complexity to your
On the other hand note that the ServiceLocator is just an abstraction over IoC (Inversion of Control) containers, which is used to obtain instances of registered components and not for registration. Therefore the lifetime of your instances
will only deppend on how they were registered into the container; in your case, if you exported a class with the
PartCreationPolicy set to NonShared, instances retrieved from the container will be kept alive as long as they are referenced by other classes.
<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML /> <o:AllowPNG /> </o:OfficeDocumentSettings> </xml><![endif]-->You'll find more information
regarding that in Chapter 3 of the Prism documentation:
Based on the aforementioned, you could consider whether using the ServiceLocator
applies to your scenario. In case it doesn't, you could consider an alternative design approach to avoid placing your view inside the xaml, so you can instantiate it through the container.
I hope you find this helpful