BaseHost.Web
1.2.32
dotnet add package BaseHost.Web --version 1.2.32
NuGet\Install-Package BaseHost.Web -Version 1.2.32
<PackageReference Include="BaseHost.Web" Version="1.2.32" />
paket add BaseHost.Web --version 1.2.32
#r "nuget: BaseHost.Web, 1.2.32"
// Install BaseHost.Web as a Cake Addin #addin nuget:?package=BaseHost.Web&version=1.2.32 // Install BaseHost.Web as a Cake Tool #tool nuget:?package=BaseHost.Web&version=1.2.32
Purpose
This is used as the foundation of my other C# projects. It provides some common bits of setup with are often needed. It sets up a configured host which uses my config module, my console module, Autofac and NLog. There is also a code generator which will create builders for any class [BuilderPattern].
How to use
Host
This is how a host can be setup, you'll need to add your own nlog config
public class Host : ConsoleHost{
public static void Main(string[] args) => new Host().Start(args);
protected override void Setup(ContainerBuilder builder){
builder.AutoActivateWith<Controller>(i => i.Start());
}
public class Controller{
public Controller(ILogger logger){...}
public void Start(){...}
}
}
Builder Generator
The generator will create a builder class, also add methods for each public property with a private mutator, With(value), Update(Func<value,value>). It will also make special use of ImmutableArray, ImmutableDictionary and ImmutableHashSet
Example model class
[BuilderPattern]
public partial class Model
{
public string Value { get; private set; }
}
generated class
public partial class Model
{
private Model () { }
public Builder AsBuilder() => Builder.BasedOn(this);
public static Builder CreateBuilder() => Builder.Instance();
public Mutable AsMutable() => new Mutable(){
Value = this.Value,
};
public Model WithValue(string value) => AsBuilder().WithValue(value).Build();
public Model UpdateValue(Func<string,string> valueFunc) => AsBuilder().UpdateValue(valueFunc).Build();
public sealed partial class Builder {
private Model _instance = new Model();
private Builder() { }
internal static Builder Instance () => new Builder();
internal static Builder BasedOn(Model reference) => Instance ()
.WithValue(reference.Value);
public Builder WithValue(string value){
_instance.Value = value;
return this;
}
public Builder UpdateValue(Func<string,string> valueFunc){
_instance.Value = valueFunc(_instance.Value);
return this;
}
public Model Build() {
var local = _instance;
_instance = null;
local = local.GetValidatedInstance();
return local;
}
}
public sealed class Mutable {
public string Value {get; set; }
public Model AsImmutable() => Model.CreateBuilder()
.WithValue(this.Value)
.Build();
}}}
Console
There are shells, console and commands. shells run on a console, and have access to commands. new commands can be registered and them will be accessible from all the consoles. There are some commands included, for shutdown/get-starting-args/config and more commands can be registered in ICommandManager
There is also a websocket interface for this.
var shutdown = new Shutdown();
_commandManager.Register("get-starting-args",args);
Config
A config can be given in the form of a json file (Host.config.json), if no json file is provided one will be generated and saved in output at runtime. Config is specified as below:
[ConfigValue(Name = "ws_pokemon_server_path", DefaultString = "ws:bhah.blah.blah:12")]
private static string ConnectionString => Config.ws_pokemon_server_path; //Config is generated at build time
Extension Methods
Lots of extension methods, covering a variety of functionality, enumerable/observables/functions ..., not really much structure, just whatever I've found useful
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- Autofac (>= 8.1.1)
- Autofac.Extensions.DependencyInjection (>= 10.0.0)
- BaseHost (>= 1.2.32)
- CommandLineParser (>= 2.9.1)
- GraphQL.Server.Ui.Playground (>= 8.1.0)
- GraphQL.Server.Ui.Voyager (>= 8.1.0)
- HotChocolate.AspNetCore (>= 14.1.0)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 9.0.0)
- Microsoft.OpenApi (>= 1.6.22)
- Newtonsoft.Json (>= 13.0.3)
- NLog (>= 5.3.4)
- NLog.Web.AspNetCore (>= 5.3.15)
- Swashbuckle.AspNetCore (>= 7.0.0)
- Swashbuckle.AspNetCore.Newtonsoft (>= 7.0.0)
- System.Collections.Immutable (>= 9.0.0)
- System.ComponentModel.Annotations (>= 5.0.0)
- System.Reactive (>= 6.0.1)
- System.Text.Json (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.32 | 40 | 11/22/2024 |
1.2.31 | 31 | 11/19/2024 |
1.2.29 | 25 | 11/18/2024 |
1.2.26 | 37 | 11/4/2024 |
1.2.25 | 34 | 11/3/2024 |
1.2.24 | 33 | 11/3/2024 |
1.2.23 | 42 | 10/22/2024 |
1.2.22 | 43 | 10/4/2024 |
1.2.21 | 46 | 9/25/2024 |
1.2.20 | 40 | 9/12/2024 |
1.2.19 | 43 | 9/2/2024 |
1.2.18 | 45 | 8/15/2024 |
1.2.17 | 45 | 8/15/2024 |
1.2.16 | 42 | 8/9/2024 |
1.2.15 | 52 | 8/9/2024 |
1.2.14 | 43 | 8/9/2024 |
1.2.13 | 40 | 8/9/2024 |
1.2.12 | 44 | 7/30/2024 |
1.2.11 | 41 | 7/30/2024 |
1.2.10 | 42 | 7/30/2024 |
1.2.7 | 60 | 7/4/2024 |
1.2.6 | 47 | 7/4/2024 |
1.2.5 | 49 | 7/3/2024 |
1.2.3 | 50 | 7/3/2024 |
0.0.200 | 51 | 7/2/2024 |
0.0.199 | 53 | 7/2/2024 |
0.0.198 | 47 | 7/2/2024 |