bootstrap your application - Envivo-Software/Envivo.Fresnel GitHub Wiki

Bootstrap your application

Within your Model Explorer project, change program.cs to the following:

WinForms:

using DomainModel;
using Envivo.Fresnel.Bootstrap.WinForms;
using Envivo.Fresnel.Features;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading;
using System.Windows.Forms;

// WinForms needs STA:
Thread.CurrentThread.SetApartmentState(ApartmentState.Unknown);
Thread.CurrentThread.SetApartmentState(ApartmentState.STA);

ApplicationConfiguration.Initialize();

var builder = new HostApplicationBuilder(args);

builder.AddFresnel(opt =>
{
    opt
    .WithModelAssemblyFrom<MyAggregateRoot>()
    .WithFeature(Feature.UI_DoodleMode, FeatureState.On)
    .WithDefaultFileLogging()
    ;
});

var host = builder.Build();

var mainForm = host.Services.GetService<BlazorWinForm>();
Application.Run(mainForm);

WebServer + Streaming:

using DomainModel;
using Envivo.Fresnel.Bootstrap.WebServer;
using Envivo.Fresnel.Features;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

builder.AddFresnel(opt =>
{
    opt
    .WithModelAssemblyFrom<MyAggregateRoot>()
    .WithFeature(Feature.UI_DoodleMode, FeatureState.On)
    .WithDefaultFileLogging()
    ;

    builder.Services.AddLogging();
});

var app = builder.Build();

app.UseFresnel();
app.UseHttpsRedirection();
app.UseAntiforgery();

await app.RunAsync();

WebAssembly:

using DomainModel;
using Envivo.Fresnel.Bootstrap.WebAssembly;
using Envivo.Fresnel.Features;
using WebAssemblyHostBuilder = Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

builder.AddFresnel(opt =>
{
    opt
    .WithModelAssemblyFrom<MyAggregateRoot>()
    .WithFeature(Feature.UI_DoodleMode, FeatureState.On)
    ;
});

var host = builder.Build();

host.UseFresnel();

await host.RunAsync();

Run this application, and you should see an empty workbench.