MiJenner.ServicesGeneric 1.5.0

dotnet add package MiJenner.ServicesGeneric --version 1.5.0
                    
NuGet\Install-Package MiJenner.ServicesGeneric -Version 1.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MiJenner.ServicesGeneric" Version="1.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MiJenner.ServicesGeneric" Version="1.5.0" />
                    
Directory.Packages.props
<PackageReference Include="MiJenner.ServicesGeneric" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MiJenner.ServicesGeneric --version 1.5.0
                    
#r "nuget: MiJenner.ServicesGeneric, 1.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MiJenner.ServicesGeneric@1.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MiJenner.ServicesGeneric&version=1.5.0
                    
Install as a Cake Addin
#tool nuget:?package=MiJenner.ServicesGeneric&version=1.5.0
                    
Install as a Cake Tool

MiJenner Services Generic

Offers a settingsmanager, a simple crud service and a few other helpers.

Settings manager

To use the settings manager you create two objects, (a) one with properties representing settings for application and (b) one with properties representing settings for users.

First, remember to add NuGet package and add:

using MiJenner.ServicesGeneric; 

You may want to use by example the following settings objects:

AppSettings appSettings = new AppSettings() { ConnString = "database.sqlite3", ApiString="anAPIstring", IsRunningOK = true };
UserSettings userSettings = new UserSettings() { UserName="Bent", WantsNotifications=false };

On desktop (Windows, macOS and Linux) you need to supply filename, application-name and company, aka organization name:

string SettingsFileName = "settings.json";
string AppName = "My App Name";
string CompanyName = "My Company Name";
FolderPolicy folderPolicy = FolderPolicy.AppDataLocal;

Next create an instance of SettingsManager as follows:

SettingsManager<AppSettings, UserSettings> settings = new SettingsManager<AppSettings, UserSettings>(SettingsFileName, AppName, CompanyName, folderPolicy, appSettings, userSettings);

Next call Initialize() on the instance to make software search for settings file. SettingsManager will first look in folder formed using AppName, CompanyName and folderPolicy, if found we are good to go. Next, it will look in the software installation location (copy-to-output) and if found it will copy to first-mentioned folder. Finally, if without luck in both locations it will create one from software, based on the objects fed into SettingsManager.

await settings.Initialize(); 

Now you can read and modify settings using normal "dot-notation", by example:

userSettings.UserName = "John Doe";
appSettings.ApiString = "Application Programming Interface"; 

You may want to save to disk, so the settings are available next time you run the application:

await settings.SaveSettingsToDiskAsync();

Note: Since we feed reference types into SettingsManager it doesn't matter if you refer to the settings directly, or via SettingsManager. In a Console application below will give the same output:

Console.WriteLine($"    - {nameof(appSettings.ConnString)}: {appSettings.ConnString}");
Console.WriteLine($"    - {nameof(settings.AppSettings.ConnString)}: {settings.AppSettings.ConnString}");

CRUD service In-Memory

Offers a simple CRUD service for quick and dirty testing of apps needing one.

Model

Model must be simple, a list of objects. Two requirements: (a) Model must inherit from IHasGuid, and (b) it must have a property called Id of type Guid. Example:

public class Item : IHasGuid 
{
   public Guid Id { get; set; }
   public required string Name { get; set; }
   public string? Description { get; set; }
}

Interface

Interface: ICrudIdService

Implementation

Implementation: CrudIdServiceInMemory

Example usage

After having created a Model as shown above, then you can create a list of these objects using:

ICrudIdService<Item> crudIdService = new CrudIdInMemory<Item>();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.5.0 195 10/21/2024
1.4.0 171 10/21/2024
1.3.0 182 10/19/2024
1.2.0 192 10/18/2024
1.1.0 201 10/18/2024
1.0.0 178 10/15/2024

Initial release.