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

Commit

Permalink
* Remove ServiceProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbrandenburg committed Mar 15, 2016
1 parent dd18606 commit 1ae1cdb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
19 changes: 4 additions & 15 deletions src/Microsoft.AspNetCore.Mvc.Core/ControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ public abstract class ControllerBase
private IObjectModelValidator _objectValidator;
private IUrlHelper _url;

/// <summary>
/// Gets the request-specific <see cref="IServiceProvider"/>.
/// </summary>
public IServiceProvider Resolver
{
get
{
return HttpContext?.RequestServices;
}
}

/// <summary>
/// Gets the <see cref="Http.HttpContext"/> for the executing action.
/// </summary>
Expand Down Expand Up @@ -136,7 +125,7 @@ public IModelMetadataProvider MetadataProvider
{
if (_metadataProvider == null)
{
_metadataProvider = Resolver?.GetRequiredService<IModelMetadataProvider>();
_metadataProvider = HttpContext?.RequestServices?.GetRequiredService<IModelMetadataProvider>();
}

return _metadataProvider;
Expand All @@ -161,7 +150,7 @@ public IUrlHelper Url
{
if (_url == null)
{
var factory = Resolver?.GetRequiredService<IUrlHelperFactory>();
var factory = HttpContext?.RequestServices?.GetRequiredService<IUrlHelperFactory>();
_url = factory?.GetUrlHelper(ControllerContext);
}

Expand All @@ -187,7 +176,7 @@ public IObjectModelValidator ObjectValidator
{
if (_objectValidator == null)
{
_objectValidator = Resolver?.GetRequiredService<IObjectModelValidator>();
_objectValidator = HttpContext?.RequestServices?.GetRequiredService<IObjectModelValidator>();
}

return _objectValidator;
Expand Down Expand Up @@ -1429,7 +1418,7 @@ public virtual bool TryValidateModel(
{
throw new ArgumentNullException(nameof(model));
}

ObjectValidator.Validate(
ControllerContext,
new CompositeModelValidatorProvider(ControllerContext.ValidatorProviders),
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.AspNetCore.Mvc.ViewFeatures/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ITempDataDictionary TempData
{
if (_tempData == null)
{
var factory = Resolver?.GetRequiredService<ITempDataDictionaryFactory>();
var factory = HttpContext?.RequestServices?.GetRequiredService<ITempDataDictionaryFactory>();
_tempData = factory?.GetTempData(HttpContext);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ public void ControllerExposes_RequestServices()
controller.ControllerContext.HttpContext = httpContext.Object;

// Act
var innerServiceProvider = controller.Resolver;
var innerServiceProvider = controller.HttpContext?.RequestServices;

// Assert
Assert.Same(serviceProvider, innerServiceProvider);
Expand Down
2 changes: 1 addition & 1 deletion test/WebSites/BasicWebSite/Controllers/OrderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public int GetServiceOrder(string serviceType, string actualType)

var queryType = typeof(IEnumerable<>).MakeGenericType(elementType);

var services = (IEnumerable<object>)Resolver.GetService(queryType);
var services = (IEnumerable<object>)HttpContext?.RequestServices.GetService(queryType);
foreach (var service in services)
{
if (actualType != null && service.GetType().AssemblyQualifiedName == actualType)
Expand Down

0 comments on commit 1ae1cdb

Please sign in to comment.