-
-
Notifications
You must be signed in to change notification settings - Fork 763
Expose DefaultViewServiceOption list props as IEnumerables. #3050
base: dev
Are you sure you want to change the base?
Conversation
@johnkors, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
Ok, will visit once we have a v3 branch. Thx |
Hi all, public class BrandedViewService : DefaultViewService
{
private static readonly string BrandAcr = "brand";
public BrandedViewService(DefaultViewServiceOptions config, IViewLoader viewLoader) : base(config, viewLoader)
{
// Disable views to re-render styles correctly
config.CacheViews = false;
// Remove any branding stylesheets from previous config
config.Stylesheets = new DefaultViewServiceOptions().Stylesheets;
// Logic for branding
var req = HttpContext.Current.Request;
var env = req.GetOwinContext().Environment;
var signInId = req["signin"];
if (signInId == null)
return;
var signInMessage = env.GetSignInMessage(signInId);
var brand = signInMessage?.AcrValues?.FirstOrDefault(acr => acr.StartsWith(BrandAcr + ":", System.StringComparison.Ordinal))?.Substring(BrandAcr.Length + 1);
if (brand != null)
{
config.Stylesheets.Add("~/IdentityServer/Brands/test.css");
}
}
} I am registering the dependency as follows: factory.ViewService = new DefaultViewServiceRegistration<IdentityServer.BrandedViewService>()
{
Mode = RegistrationMode.InstancePerHttpRequest
}; I am commenting here because this pull request might solve the issue or at least allow me to do this in a cleaner fashion. |
@MrJerB , the work-around for now is to not mutate the singleton-scoped config's lists. For example:
|
Thanks @johnkors and another plus one for showing me how to obtain the OWIN context through dependency injection 👍 |
Fixes #2947. NB! Breaking change & needs a bump of major.
The
DefaultViewServiceOption
/DefaultViewServiceRegistration
allows mutating state on a registred singleton, causing possible bad side effects. This PR changes the option API to use IEnumerable instead of IList - restricting access to modify the list directly.Example of a bad side effect caused by modifying one of the lists in a class inheriting from the
DefaultViewService
: #2089 (comment)