Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Changes per PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed May 19, 2017
1 parent 0b1c44b commit 0baba4d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private InnerCache CurrentCache
else
{
// Filter instances from statically defined filter descriptors + from filter providers
filters = FilterFactory.CreateUncachedFilters(_filterProviders, controllerContext, cacheEntry.Filters);
filters = FilterFactory.CreateUncachedFilters(_filterProviders, controllerContext, cacheEntry.CachedFilters);
}

return (cacheEntry, filters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Mvc.Internal
public class ControllerActionInvokerCacheEntry
{
internal ControllerActionInvokerCacheEntry(
FilterItem[] filters,
FilterItem[] cachedFilters,
Func<ControllerContext, object> controllerFactory,
Action<ControllerContext, object> controllerReleaser,
ControllerBinderDelegate controllerBinderDelegate,
Expand All @@ -19,11 +19,11 @@ internal ControllerActionInvokerCacheEntry(
ControllerFactory = controllerFactory;
ControllerReleaser = controllerReleaser;
ControllerBinderDelegate = controllerBinderDelegate;
Filters = filters;
CachedFilters = cachedFilters;
ActionMethodExecutor = actionMethodExecutor;
}

public FilterItem[] Filters { get; }
public FilterItem[] CachedFilters { get; }

public Func<ControllerContext, object> ControllerFactory { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Core;
using Microsoft.Extensions.Internal;
Expand All @@ -13,14 +14,18 @@ namespace Microsoft.AspNetCore.Mvc.Internal
{
public class DefaultControllerPropertyActivator : IControllerPropertyActivator
{
private readonly object _initializeLock = new object();
private static readonly Func<Type, PropertyActivator<ControllerContext>[]> _getPropertiesToActivate =
GetPropertiesToActivate;
private object _initializeLock = new object();
private bool _initialized;
private ConcurrentDictionary<Type, PropertyActivator<ControllerContext>[]> _activateActions;
private Func<Type, PropertyActivator<ControllerContext>[]> _getPropertiesToActivate;

public void Activate(ControllerContext context, object controller)
{
EnsureInitialized();
LazyInitializer.EnsureInitialized(
ref _activateActions,
ref _initialized,
ref _initializeLock);

var controllerType = controller.GetType();
var propertiesToActivate = _activateActions.GetOrAdd(
Expand Down Expand Up @@ -62,20 +67,8 @@ void Activate(ControllerContext controllerContext, object controller)

return Activate;
}
private void EnsureInitialized()
{
lock (_initializeLock)
{
if (!_initialized)
{
_activateActions = new ConcurrentDictionary<Type, PropertyActivator<ControllerContext>[]>();
_getPropertiesToActivate = GetPropertiesToActivate;
_initialized = true;
}
}
}

private PropertyActivator<ControllerContext>[] GetPropertiesToActivate(Type type)
private static PropertyActivator<ControllerContext>[] GetPropertiesToActivate(Type type)
{
IEnumerable<PropertyActivator<ControllerContext>> activators;
activators = PropertyActivator<ControllerContext>.GetPropertiesToActivate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Concurrent;
using System.Threading;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding;
Expand All @@ -12,20 +13,25 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{
public class ViewDataDictionaryControllerPropertyActivator : IControllerPropertyActivator
{
private readonly object _initializeLock = new object();
private readonly Func<Type, PropertyActivator<ControllerContext>[]> _getPropertiesToActivate;
private readonly IModelMetadataProvider _modelMetadataProvider;
private bool _initialized;
private ConcurrentDictionary<Type, PropertyActivator<ControllerContext>[]> _activateActions;
private Func<Type, PropertyActivator<ControllerContext>[]> _getPropertiesToActivate;
private bool _initialized;
private object _initializeLock = new object();

public ViewDataDictionaryControllerPropertyActivator(IModelMetadataProvider modelMetadataProvider)
{
_modelMetadataProvider = modelMetadataProvider;
_getPropertiesToActivate = GetPropertiesToActivate;
}

public void Activate(ControllerContext actionContext, object controller)
{
EnsureInitialized();
LazyInitializer.EnsureInitialized(
ref _activateActions,
ref _initialized,
ref _initializeLock);

var controllerType = controller.GetType();
var propertiesToActivate = _activateActions.GetOrAdd(
controllerType,
Expand Down Expand Up @@ -63,19 +69,6 @@ void Activate(ControllerContext controllerContext, object controller)
return Activate;
}

private void EnsureInitialized()
{
lock (_initializeLock)
{
if (!_initialized)
{
_activateActions = new ConcurrentDictionary<Type, PropertyActivator<ControllerContext>[]>();
_getPropertiesToActivate = GetPropertiesToActivate;
_initialized = true;
}
}
}

private PropertyActivator<ControllerContext>[] GetPropertiesToActivate(Type type)
{
var activators = PropertyActivator<ControllerContext>.GetPropertiesToActivate(
Expand Down

0 comments on commit 0baba4d

Please sign in to comment.