diff --git a/README.md b/README.md index 10edfb4..f259dcb 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,22 @@ This will automatically initialize following extensions. ## Available content Please find a list of available content below. +### Utilities + +#### UserSecretsManager +The `UserSecretsManager` helps you to manage your user secrets in your application. It reads the `secrets.json` file stored in the user profile folder. + +```cs +if (Assembly is null) +{ + Assembly = IntrospectionExtensions.GetTypeInfo(typeof(MauiProgram)).Assembly; + UserSecretsManager.Settings = new UserSecretsManager.UserSecretsManagerBuilder() + .WithAppNamespace("SharedMauiXamlStylesLibrary.SampleApp") + .WithCustomAssambly(Assembly) + .Build(); +} +``` + ### Behaviors #### Namespace diff --git a/src/SharedNetCoreLibrary/Utilities/UserSecretsManager.cs b/src/SharedNetCoreLibrary/Utilities/UserSecretsManager.cs index f3c5cec..1168a7f 100644 --- a/src/SharedNetCoreLibrary/Utilities/UserSecretsManager.cs +++ b/src/SharedNetCoreLibrary/Utilities/UserSecretsManager.cs @@ -64,6 +64,10 @@ public UserSecretsManager(string appNamespace, string userSecretsFileName) AppNamespace = appNamespace; UserSecretsFileName = userSecretsFileName; } + public UserSecretsManager(string appNamespace, string userSecretsFileName, Assembly assembly) : this(appNamespace, userSecretsFileName) + { + CurrentAssembly = assembly; + } #endregion #region Methods @@ -72,7 +76,16 @@ public void Initialize(Assembly? assembly = null) { try { - CurrentAssembly ??= GetAssembly(typeof(UserSecretsManager)); + // Override in case a custom assembly is provided + if (assembly is not null) + CurrentAssembly = assembly; +#if NET8_0_OR_GREATER + ArgumentNullException.ThrowIfNull(CurrentAssembly, nameof(CurrentAssembly)); +#else + if (CurrentAssembly is null) + throw new ArgumentNullException($"The `{nameof(CurrentAssembly)}` cannot be null!"); +#endif + //CurrentAssembly ??= GetAssembly(typeof(UserSecretsManager)); Stream? stream = CurrentAssembly?.GetManifestResourceStream($"{AppNamespace}.{UserSecretsFileName}"); if (stream is not null) {