MiJenner.ServicesGeneric
1.5.0
dotnet add package MiJenner.ServicesGeneric --version 1.5.0
NuGet\Install-Package MiJenner.ServicesGeneric -Version 1.5.0
<PackageReference Include="MiJenner.ServicesGeneric" Version="1.5.0" />
<PackageVersion Include="MiJenner.ServicesGeneric" Version="1.5.0" />
<PackageReference Include="MiJenner.ServicesGeneric" />
paket add MiJenner.ServicesGeneric --version 1.5.0
#r "nuget: MiJenner.ServicesGeneric, 1.5.0"
#:package MiJenner.ServicesGeneric@1.5.0
#addin nuget:?package=MiJenner.ServicesGeneric&version=1.5.0
#tool nuget:?package=MiJenner.ServicesGeneric&version=1.5.0
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 | Versions 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. |
-
net8.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Json (>= 8.0.1)
- Newtonsoft.Json (>= 13.0.3)
- sqlite-net-pcl (>= 1.9.172)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release.