Skip to content

Latest commit

 

History

History
119 lines (99 loc) · 3.9 KB

bootstrapping.md

File metadata and controls

119 lines (99 loc) · 3.9 KB
layout title subtitle
page
Bootstrapping
Extend everything

Every great application starts small. In our case we want to show a simple text inside the first view. This can be done in a few simple steps:

Open Visual Studio or any other IDE you're familiar with.

Create a new client-side .NET project for the platform of your choice. We will use WPF here for the sake of simplicity but you can use anything.

If you have chosen WPF you should see App.xaml, App.xaml.cs and MainWindow.xaml files

Now we would like to use the Bootstrapping component of the LogoFX framework to make things easier and more extensible:

Install the package via package manager or command-line: Install-Package LogoFX.Client.Bootstrapping This is the main bootstrapping package. In this particular example we will install one more package which will be covered in another topic. For now install it by typing Install-Package LogoFX.Client.Bootstrapping.Adapters.SimpleContainer

Then go ahead and add a file named AppBootstrapper.cs. This file should include the following code

using LogoFX.Client.Bootstrapping.Adapters.SimpleContainer;
using LogoFX.Client.Bootstrapping.Samples.WPF.ViewModels;

namespace LogoFX.Client.Bootstrapping.Samples.WPF
{
   public class AppBootstrapper : 
   BootstrapperContainerBase<ExtendedSimpleContainerAdapter>
   .WithRootObject<ShellViewModel>
   {
      public AppBootstrapper()
         :base (new ExtendedSimpleContainerAdapter())
      {
			
      }
   }
}

Go ahead and try to compile the code. It won't compile complaining about missing ShellViewModel. Indeed we haven't added our first view-model to the application (If you're not familiar with MVVM, please refer to this amazing resourse)

Let's add the view-model and its view. Create a folder named ViewModels at the root level of your application and add a file there named ShellViewModel.cs:

namespace LogoFX.Client.Bootstrapping.Samples.WPF.ViewModels
{
    public class ShellViewModel
    {
        public string DisplayName => "Samples.Bootstrapping";
    }
}

The view is still missing so we should add it as well. Create a folder named Views at the root level of your application and add a file there named ShellView.xaml (add it via Create Window option) Delete the code-behind portion of this file and the following markup to the file itself:

<Window 
x:Class="LogoFX.Client.Bootstrapping.Samples.WPF.Views.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewModels="clr-namespace:LogoFX.Client.Bootstrapping.Samples.WPF.ViewModels"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance viewModels:ShellViewModel}"
Title="{Binding DisplayName, Mode=OneTime}"
Height="350" Width="350">

    <Grid>
        <TextBlock Text="Hello Bootstrapping" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="24" />
    </Grid>

</Window>

The only missing part is the link between the app's entry point and the bootstrapper: Delete the MainWindow.xaml and modify the App.xaml and App.xaml.cs files:

App.xaml

<Application 
x:Class="LogoFX.Client.Bootstrapping.Samples.WPF.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />

App.xaml.cs

namespace LogoFX.Client.Bootstrapping.Samples.WPF
{    
   public partial class App
   {
      public App()
      {
         var appBootstrapper = new AppBootstrapper();
         appBootstrapper.Initialize();
      }
   }
}

That's it! Build the solution and run it. You should see something like this:

alt text