Dapplo.Microsoft.Extensions.Hosting icon indicating copy to clipboard operation
Dapplo.Microsoft.Extensions.Hosting copied to clipboard

Alternative to IWpfShell

Open mgnslndh opened this issue 3 years ago • 2 comments

Hi Robin!

I've been playing around some more with the library and I wonder if it would be possible to find an alternative solution to the IWpfShell marker interface. Let's say that the shell is located in separate assembly from the host. It would be nice to avoid the dependency on the marker interface in that case.

Perhaps the API could have a method UsingWpfShell<TShell>() instead and use the provided type for lookup.

Or would you say this is out of scope and rather recommend using a custom implementation of ConfigureWpf alltogether?

mgnslndh avatar Dec 17 '20 21:12 mgnslndh

I worked around this by not using the IWpfShell interface at all and instead used the following startup code:

public partial class MyApplication : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        MainWindow = new ShellView();
        MainWindow.Show();
        MainWindow.Activate();
        base.OnStartup(e);
    }
}

mgnslndh avatar Dec 18 '20 16:12 mgnslndh

Hi Magnus,

sorry for the delay, so much to do...

I agree that if you want to provide your shell in a separate assembly, it's unfortunate to add a dependency to my library. My assumption was that in most cases you'd use a plugin (IPlugin), so it can configure the dependencies, which needs dependencies anyway. But as you already saw, there is no direct NEED to use IWpfShell, this is only a convenience to make automatically open a window.

FYI: The logic for the IWpfShel can be found here: https://github.com/dapplo/Dapplo.Microsoft.Extensions.Hosting/blob/master/src/Dapplo.Microsoft.Extensions.Hosting.Wpf/Internals/WpfThread.cs#L69

You also don't NEED an application, but it's possible to override it's behavior to do exactly that what you did.

I'm sure I can extend the configuration to add something that will add a similar behavior, without the need for you to add dependencies, but I prefer to keep the configuration small & simple as it will get way to many border-cases. But I'm always happy to discuss this!

If you are happy with your current solution, let me know and we can close this issue.

P.S. I'm slightly confused with your question, as the whole idea of this project is using the hosting feature to make UI's work with dependency injection right out of the box. Maybe you have a service which also needs an already written UI and you more or less don't need the added service "ballast" to your UI? So I love to hear more about your use-case, like what you are doing with this project. This helps me to predict if future enhancement / fixes are in line with what you are doing.

Best wishes, Robin

Lakritzator avatar Dec 21 '20 09:12 Lakritzator