Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

prism - Multiple shells with service lifetime associated with the shell

I have followed Brian Lagunas Pluralsight course titled "Prism Problems & Solutions: Showing Multiple Shells". I have created an application that can show multiple shells but now I want to be able to inject a new DbContext (sqlite DbContext with a different filename) using constructor injection when each MainWindowViewModel is called using constructor injection. I am guessing that I need to modify the ShellService to also manage the container but not sure how to do this. I read about scoped containers but not sure they apply to having different shells. Any help on how to proceed is appreciated.

class ShellService : IShellService
{
    private readonly IContainer _container;
    private readonly IRegionManager _regionManager;

    public ShellService(IContainer container, IRegionManager regionManager)
    {
        _container = container;
        _regionManager = regionManager;
    }
    public void ShowShell(string uri)
    {
        var shell = _container.Resolve<MainWindow>();

        var scopedRegion = _regionManager.CreateRegionManager();
        RegionManager.SetRegionManager(shell, scopedRegion);

        RegionManagerAware.SetRegionManagerAware(shell, scopedRegion);

        scopedRegion.RequestNavigate(RegionNames.ContentRegion, uri);

        shell.Show();

    }
}
question from:https://stackoverflow.com/questions/65924905/multiple-shells-with-service-lifetime-associated-with-the-shell

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...