canton7 / Stylet

A very lightweight but powerful ViewModel-First MVVM framework for WPF for .NET Framework and .NET Core, inspired by Caliburn.Micro.
MIT License
994 stars 143 forks source link

Bootstrap from a Class Library #139

Closed robigit closed 3 years ago

robigit commented 4 years ago

Hello, Is it possible to launch the bootstrapper and the ShellView from a class library ?

canton7 commented 4 years ago

You can put the bootstrapper, views, viewmodels, etc, in a class library. The actual WPF Application instance will need to come from somewhere, and the easiest way is to have an App.xaml in your main application (which references the bootstrapper defined in the class library): that's how I normally do it.

It's probably possible to even set up the Application/Dispatcher/etc in the class library, but you might have to do it manually.

robigit commented 4 years ago

Thank you for the answer. I was trying to connect my wpf class library to a not managed application. I tried with the following code and now it seems work correctly (except for a little problem that made me lost a a lot of time and that I initially ascribed to this call). Do you see any problem to do this way?

 var bootstrapper = new Bootstrapper();
 bootstrapper.Start(null);

[For completeness the problem was that before launching wpf I had to reset the floating point with the following function

        [DllImport("ucrtbase.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int _fpreset();

]

yiyecao commented 3 years ago

I'm trying to inject the class library into IOC。

canton7 commented 3 years ago

@robigit Apologies I missed message. Starting the bootstrapper without first setting it up with an application isn't supported, and things like showing IWindowManager won't be able to function.

I'm closing this as old - please re-open if you still have questions.

@yiyecao If you've got a question, please open a new issue and give enough detail for someone to be able to answer it.