![]() |
VOOZH | about |
dotnet add package Occasus.BlazorUI --version 8.1.9
NuGet\Install-Package Occasus.BlazorUI -Version 8.1.9
<PackageReference Include="Occasus.BlazorUI" Version="8.1.9" />
<PackageVersion Include="Occasus.BlazorUI" Version="8.1.9" />Directory.Packages.props
<PackageReference Include="Occasus.BlazorUI" />Project file
paket add Occasus.BlazorUI --version 8.1.9
#r "nuget: Occasus.BlazorUI, 8.1.9"
#:package Occasus.BlazorUI@8.1.9
#addin nuget:?package=Occasus.BlazorUI&version=8.1.9Install as a Cake Addin
#tool nuget:?package=Occasus.BlazorUI&version=8.1.9Install as a Cake Tool
.net core IOptions manager and UI
At it's core Occasus is an easy way to move .Net Options from the appSettings.json file to another storage repository.
It also has an optional UI to allow editing of those values during runtime.
Currently .Net core 8; Console Applications, Blazor Apps and API, and Azure Functions.
If you have a dependancy injected IConfigurationBuilder and IServiceCollection you should be good to go.
First of all you need to pick one (or more) of the repository packages for Occasus, and possibly a UI package. See more below.
Then you can use them in your configuration:
var builder = WebApplication.CreateBuilder(args);
builder.UseSettingsFrom...(options)
Where the UseSettingsFrom... is an extension from a Occasus repository package
.WithOptions<MyOptionsClass>()
Note: Here the WithOptions is an extension to the repository added to the builder.
You can also refer back to the Configured Option, just like regular Option injecting, where you can use the OptionsBuilder:
.WithOptions<MyOptions>(out var optionsBuilder);
optionsBuilder.Validate(x => x.SomeRequiredValue != null && x.ListOfStrings.Any(), "MyOptions Strings must have some value");
So you can validate on startup here too.
You can inject the .Net IOptions<MyOptionsClass> into your application.
private readonly MyOptionsClass myoptions;
public MyService(IOptionsSnapshot<MyOptionsClass> myoptions)
{
this.myoptions = myoptions.Value;
}
You can read more in the link above but if your usinbg IOptionsSnapshot, this is a Scoped access and the value will be retrieved everytime you start a new scope. This means any changes in the UI should be reflected without having to restart the application.
So if you were getting settings from SQL using the Occasus SQLEFRepository and using the Blazor UI package
var builder = WebApplication.CreateBuilder(args);
builder.AddOccasusUI()
.UseOptionsFromSQLEF(settings =>
{
settings.WithSQLConnection(sqlConnBuilder =>
{
sqlConnBuilder.ConnectionString = builder.Configuration["ConnectionStrings:SettingsConnectionString"];
});
})
.WithOptions<ApplicationOptions>()
Where ApplicationOptions is a class or record for the options from your application.
👁 GitHub last commit
👁 GitHub Workflow Status
dotnet add package Occasus.JSONRepository
Install-Package Occasus.JSONRepository
This allows you to use a .json file as a repository for settings, it also allows you to use the appSettings.json file.
Simple usage:
UseOptionsFromJsonFile(string filePath)
builder.UseOptionsFromJsonFile("settings/settings.json")
.WithOptions<ApplicationOptions>();
Advanced JSON Options:
UseOptionsFromJsonFile(string filePath, Action<JsonSourceSettings> jsonSourceSettings)
builder.UseOptionsFromJsonFile("appsettings.json", settings =>
{
settings.JsonWriterOptions((ref JsonWriterOptions options) => options.Indented = true);
settings.JsonNodeOptions((ref JsonNodeOptions options) => options.PropertyNameCaseInsensitive = true);
})
.WithOptions<TestAppSettingsJson>();
JsonSourceSettings is a class that configures the repository:
Occasus.JsonRepository uses System.Text.Json and the following actions are passed directly to that:
👁 GitHub last commit
👁 GitHub Workflow Status
dotnet add package Occasus.SQLRepository
Install-Package Occasus.SQLRepository
👁 GitHub last commit
👁 GitHub Workflow Status
dotnet add package Occasus.SQLEFRepository
Install-Package Occasus.SQLEFRepository
This allows you to use a SQL Server for settings.
Usage example:
builder.AddOccasusUI()
.UseOptionsFromSQL(settings =>
{
settings.EncryptSettings = true;
settings.EncryptionKey = "a password";
settings.WithSQLConnection(sqlConnBuilder =>
{
sqlConnBuilder.ConnectionString = builder.Configuration["ConnectionStrings:SettingsConnectionString"];
sqlConnBuilder.PersistSecurityInfo = true;
});
})
Using EF DbOptions example:
...
.UseOptionsFromSQLEF(settings =>
{
...
settings.WithSQLConnection(sqlConnBuilder =>
{
sqlConnBuilder.ConnectionString = builder.Configuration["ConnectionStrings:SettingsConnectionString"];
}, dbOptions =>
{
dbOptions.EnableRetryOnFailure(3, new(0, 0, 5), null);
});
})
SQLEFSourceSettings is a class that configures the repository:
SQLEFSourceSettings has a handy WithSQLConnection(Action<SqlConnectionStringBuilder> builder, Action\<SqlServerDbContextOptionsBuilder>? sqlServerDbContextOptionsBuilder) method
SQLSourceSettings has a handy WithSQLConnection(Action<SqlConnectionStringBuilder> builder) method
These allow you to build the connection string and the DbContext options fluently, like you would any normal SQL Connection.
System.Data.SqlClient.SqlConnectionStringBuilder
Microsoft.EntityFrameworkCore.Infrastructure.SqlServerDbContextOptionsBuilder
AES is provided by System.Security.Cryptography
BlockBitSize = 128;
KeyBitSize = 256;
SaltBitSize = 64;
Iterations = 10000;
👁 GitHub last commit
👁 GitHub Workflow Status
dotnet add package Occasus.BlazorUI
Install-Package Occasus.BlazorUI
The Blazor UI package adds a UI component to the configurable path /occasus
Simple usage:
var builder = WebApplication.CreateBuilder(args);
builder.AddOccasusUI()
var app = builder.Build();
app.UseOccasusUI("mypassword");
Or if you need to move Occasus to another URL you can use:
var app = builder.Build();
app.UseOccasusUI("mypassword", "/other");
You can decorate your Options Class with several attributes to determing how the control is shown in the UI.
public record UserDetails
{
[Display(Name = "A User Name"), Required]
public string? User { get; set; }
[Input(InputType.Password), RestartRequired]
public string? Password { get; set; }
}
The 'RestartRequired' attribute is used to tell the UI to display a message whenever the class or the property (depending on where you put the Attribute) is changed, that the application needs restarting for the option to have an effect. Note: Whether or not the option has an effect is down to your application, Occasus will change it real time regardless.
👁 GitHub last commit
👁 GitHub Workflow Status
dotnet add package Occasus.FeatureManagement
Install-Package Occasus.FeatureManagement
FeatureManagement integrates with Microsoft.FeatureManagement.AspNetCore
Usage:
.WithFeatureFlagOptions<FeatureManagement>(builder.Configuration);
In order to add feature flags the method requres the IConfiguration interface. This makes it hard to use with Console Apps and Azure Functions. But the inteded use of Feature Flags is API and UI apps.
WithFeatureFlagOptions also supports the OptionsBuilder parameter.
Example Feature Flag (This is using the standard .Net feature)
public FeatureManagedService(IFeatureManager featureManager)
{
...
}
public string GetValue(string flag)
{
...
return featureManager.IsEnabledAsync(flag) ? "Yes" : "No";
}
As you can see feature flags are only ever booleans, and as such a feature flag class added to Occasus should just be booleans. However, the FeatureManagement system from Microsoft does support extended information to vary the feature flag by various different inputs. This, in theory should still work with Occasus if you structure your class correctly. It is untested at this time.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.1.9 | 608 | 6/4/2024 |
| 8.1.8 | 258 | 6/4/2024 |
| 8.1.7 | 269 | 6/4/2024 |
| 8.1.6 | 356 | 5/14/2024 |
| 8.1.4 | 271 | 5/14/2024 |
| 8.1.3 | 543 | 3/11/2024 |
| 8.1.1 | 239 | 3/11/2024 |
| 7.0.13 | 254 | 3/11/2024 |
| 7.0.12 | 268 | 3/11/2024 |
| 7.0.11 | 276 | 3/11/2024 |
| 7.0.9 | 281 | 3/9/2024 |
| 7.0.8 | 291 | 3/9/2024 |
| 7.0.7 | 567 | 2/22/2024 |
| 7.0.6 | 488 | 12/8/2023 |
| 6.0.55 | 412 | 10/19/2023 |
| 6.0.54 | 250 | 10/19/2023 |
| 6.0.53 | 268 | 10/19/2023 |
| 6.0.51 | 231 | 10/18/2023 |
| 6.0.50 | 550 | 7/20/2023 |
| 6.0.49 | 662 | 2/10/2023 |