Created
January 31, 2022 09:52
-
-
Save svenrog/6041709745b8f848dee1b93a7c1faa83 to your computer and use it in GitHub Desktop.
Reference implementation of ApplicationOptionsPostConfigurer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using EPiServer.Cms.UI.AspNetIdentity; | |
using EPiServer.Data; | |
using Microsoft.Extensions.Options; | |
using System.Linq; | |
namespace YourProject.Infrastructure.Security | |
{ | |
public class ApplicationOptionsPostConfigurer : IPostConfigureOptions<ApplicationOptions> | |
{ | |
private readonly IOptions<DataAccessOptions> _dataAccessOptions; | |
public ApplicationOptionsPostConfigurer(IOptions<DataAccessOptions> dataAccessOptions) | |
{ | |
_dataAccessOptions = dataAccessOptions; | |
} | |
public void PostConfigure(string name, ApplicationOptions options) | |
{ | |
if (string.IsNullOrEmpty(options.ConnectionStringOptions?.ConnectionString)) | |
{ | |
options.ConnectionStringOptions = _dataAccessOptions.Value.ConnectionStrings.FirstOrDefault((ConnectionStringOptions c) => c.Name == _dataAccessOptions.Value.DefaultConnectionStringName); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment