32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System;
|
|
using Microsoft.Framework.DependencyInjection;
|
|
|
|
namespace Microsoft.AspNet.Mvc
|
|
{
|
|
/// <summary>
|
|
/// <see cref="IControllerActivator"/> that uses type activation to create controllers.
|
|
/// </summary>
|
|
public class DefaultControllerActivator : IControllerActivator
|
|
{
|
|
private readonly ITypeActivatorCache _typeActivatorCache;
|
|
|
|
/// <summary>
|
|
/// Creates a new <see cref="DefaultControllerActivator"/>.
|
|
/// </summary>
|
|
/// <param name="typeActivatorCache">The <see cref="ITypeActivatorCache"/>.</param>
|
|
public DefaultControllerActivator(ITypeActivatorCache typeActivatorCache)
|
|
{
|
|
_typeActivatorCache = typeActivatorCache;
|
|
}
|
|
/// <inheritdoc />
|
|
public object Create([NotNull] ActionContext actionContext, [NotNull] Type controllerType)
|
|
{
|
|
var serviceProvider = actionContext.HttpContext.RequestServices;
|
|
return _typeActivatorCache.CreateInstance<object>(serviceProvider, controllerType);
|
|
}
|
|
}
|
|
}
|