ToolBX.AssemblyInitializer
2.2.0-beta2
See the version list below for details.
dotnet add package ToolBX.AssemblyInitializer --version 2.2.0-beta2
NuGet\Install-Package ToolBX.AssemblyInitializer -Version 2.2.0-beta2
<PackageReference Include="ToolBX.AssemblyInitializer" Version="2.2.0-beta2" />
paket add ToolBX.AssemblyInitializer --version 2.2.0-beta2
#r "nuget: ToolBX.AssemblyInitializer, 2.2.0-beta2"
// Install ToolBX.AssemblyInitializer as a Cake Addin #addin nuget:?package=ToolBX.AssemblyInitializer&version=2.2.0-beta2&prerelease // Install ToolBX.AssemblyInitializer as a Cake Tool #tool nuget:?package=ToolBX.AssemblyInitializer&version=2.2.0-beta2&prerelease
AssemblyInitializer
Helps decouple initialization logic by splitting it into AssemblyInitializer classes.
Good to know
This package includes the AutoInject library. It also automatically initializes AutoInject so you don�t need to think about it at all. Just put those [AutoInject] attributes on the classes you want to inject and you�re good to go.
For console applications, it also grants you the possibility to optionally use an appsettings.json file right out of the box.
Getting started
Put your initialization logic inside AssemblyInitializer classes. You�re free to call them whatever you want so long as they implement the IAssemblyInitializer interface.
public class SomeAssemblyInitializer : IAssemblyInitializer
{
public void Configure(IServiceCollection services, IConfiguration configuration)
{
//This is where you would normally manually inject your services but you don't need to do that if you're using AutoInject
//But if you really don't like AutoInject for some reason or can't use it because what you need to inject is from a third party
services.AddSingleton<ISomeService, SomeService>();
}
public void Configure(IApplicationBuilder app, IHostEnvironment env)
{
//I need to do this in Rough Trigger to initialize some loading logic
var configurator = app.ApplicationServices.GetRequiredService<IConfigurator>();
configurator.InitializeCurrentUserApplicationDataPath();
}
}
Setup
Web
All you need to do is for your Startup class to inherit from AutoStartup.
Console
There are a few more steps involved for Console applications. Be sure to grab the AssemblyInitializer.Console package instead of simply AssemblyInitializer.
First, you need to add a Startup class that inherits ConsoleStartup like this.
Then, in your Program.cs file you should call the ConsoleHost like this.
And you�re good to go!
Why
The goal of this library is to unify the way initialization is done across all application types. It also has the added advantage of decoupling initialization logic from the rest of your code or even from itself.
You can have as many AssemblyInitializers as you want so you could have one per concern if your initialization code is particularly crowded.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net7.0
- Microsoft.Extensions.Hosting.Abstractions (>= 7.0.0)
- ToolBX.AutoConfig (>= 2.2.0-beta1)
- ToolBX.AutoInject (>= 2.2.0-beta3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ToolBX.AssemblyInitializer:
Package | Downloads |
---|---|
ToolBX.AssemblyInitializer.Console
Helps decouple initialization logic by splitting it into AssemblyInitializer classes. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.0.0 | 1,156 | 9/26/2024 |
3.0.0-beta2 | 121 | 9/23/2024 |
3.0.0-beta-1 | 139 | 2/7/2024 |
2.2.0 | 819 | 1/12/2024 |
2.2.0-beta5 | 160 | 1/7/2024 |
2.2.0-beta4 | 168 | 12/13/2023 |
2.2.0-beta2 | 165 | 11/16/2023 |
2.2.0-beta1 | 145 | 7/26/2023 |
2.0.2 | 210 | 6/19/2023 |
2.0.1 | 250 | 4/25/2023 |
2.0.0 | 388 | 11/11/2022 |
2.0.0-beta2 | 164 | 9/21/2022 |
2.0.0-beta1 | 179 | 9/21/2022 |
1.0.1 | 497 | 9/21/2022 |
1.0.0 | 557 | 3/3/2022 |