Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/SharedNetCoreLibrary/Utilities/UserSecretsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand Down
Loading