diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentActivator.cs b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentActivator.cs
index 2d5f5eb5d4..8920bfd695 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentActivator.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentActivator.cs
@@ -3,40 +3,43 @@
using System;
using System.Collections.Concurrent;
-using System.Collections.Generic;
using System.Reflection;
-using Microsoft.AspNet.Mvc.Rendering;
-using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ViewComponents
{
///
- /// Represents the that is registered by default.
+ /// A default implementation of .
///
+ ///
+ /// The can provide the current instance of
+ /// to a public property of a view component marked
+ /// with .
+ ///
public class DefaultViewComponentActivator : IViewComponentActivator
{
- private readonly Func[]> _getPropertiesToActivate;
- private readonly IDictionary> _valueAccessorLookup;
- private readonly ConcurrentDictionary[]> _injectActions;
+ private readonly Func[]> _getPropertiesToActivate;
+ private readonly ConcurrentDictionary[]> _injectActions;
///
/// Initializes a new instance of class.
///
public DefaultViewComponentActivator()
{
- _valueAccessorLookup = CreateValueAccessorLookup();
- _injectActions = new ConcurrentDictionary[]>();
+ _injectActions = new ConcurrentDictionary[]>();
_getPropertiesToActivate = type =>
- PropertyActivator.GetPropertiesToActivate(
- type, typeof(ActivateAttribute), CreateActivateInfo);
+ PropertyActivator.GetPropertiesToActivate(
+ type,
+ typeof(ViewComponentContextAttribute),
+ CreateActivateInfo);
}
///
- public virtual void Activate([NotNull] object viewComponent, [NotNull] ViewContext context)
+ public virtual void Activate([NotNull] object viewComponent, [NotNull] ViewComponentContext context)
{
- var propertiesToActivate = _injectActions.GetOrAdd(viewComponent.GetType(),
- _getPropertiesToActivate);
+ var propertiesToActivate = _injectActions.GetOrAdd(
+ viewComponent.GetType(),
+ _getPropertiesToActivate);
for (var i = 0; i < propertiesToActivate.Length; i++)
{
@@ -45,44 +48,9 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
}
}
- ///
- /// Creates a lookup dictionary for the values to be activated.
- ///
- /// Returns a readonly dictionary of the values corresponding to the types.
- protected virtual IDictionary> CreateValueAccessorLookup()
+ private PropertyActivator CreateActivateInfo(PropertyInfo property)
{
- return new Dictionary>
- {
- { typeof(ViewContext), (context) => context },
- {
- typeof(ViewDataDictionary),
- (context) =>
- {
- return new ViewDataDictionary(context.ViewData);
- }
- }
- };
- }
-
- private PropertyActivator CreateActivateInfo(PropertyInfo property)
- {
- Func valueAccessor;
- if (!_valueAccessorLookup.TryGetValue(property.PropertyType, out valueAccessor))
- {
- valueAccessor = (viewContext) =>
- {
- var serviceProvider = viewContext.HttpContext.RequestServices;
- var service = serviceProvider.GetRequiredService(property.PropertyType);
- if (typeof(ICanHasViewContext).IsAssignableFrom(property.PropertyType))
- {
- ((ICanHasViewContext)service).Contextualize(viewContext);
- }
-
- return service;
- };
- }
-
- return new PropertyActivator(property, valueAccessor);
+ return new PropertyActivator(property, context => context);
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentInvoker.cs b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentInvoker.cs
index 8c6d405499..5137346e8e 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentInvoker.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/DefaultViewComponentInvoker.cs
@@ -80,7 +80,7 @@ namespace Microsoft.AspNet.Mvc.ViewComponents
var component = _typeActivatorCache.CreateInstance