Browse Source

React to API changes in aspnet/Mvc

f638c051fa
pull/79/head
Josh Comley 10 years ago
committed by Kévin Chalet
parent
commit
5d0bfc9b4a
  1. 38
      src/OpenIddict.Mvc/OpenIddictExtensions.cs

38
src/OpenIddict.Mvc/OpenIddictExtensions.cs

@ -5,13 +5,14 @@
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Razor.Compilation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
@ -53,11 +54,15 @@ namespace Microsoft.AspNetCore.Builder {
var configuration = app.ApplicationServices.GetRequiredService<OpenIddictConfiguration>();
services.AddMvc()
// Register the OpenIddict controller.
.AddControllersAsServices(new[] {
typeof(OpenIddictController<,>).MakeGenericType(configuration.UserType, configuration.ApplicationType)
// Note: ConfigureApplicationPartManager() must be
// called before AddControllersAsServices().
.ConfigureApplicationPartManager(manager => {
manager.ApplicationParts.Clear();
manager.ApplicationParts.Add(new OpenIddictPart(configuration));
})
.AddControllersAsServices()
// Add an OpenIddict-specific convention to ensure that the generic
// OpenIddictController gets an appropriate controller name.
.AddMvcOptions(options => options.Conventions.Add(new OpenIddictConvention()))
@ -110,16 +115,6 @@ namespace Microsoft.AspNetCore.Builder {
return container.GetRequiredService(typeof(UserManager<>).MakeGenericType(configuration.UserType));
});
// Register the assembly provider in the isolated container.
services.AddScoped(provider => {
var accessor = provider.GetRequiredService<IHttpContextAccessor>();
var container = (IServiceProvider) accessor.HttpContext.Items[typeof(IServiceProvider)];
Debug.Assert(container != null);
// Resolve the assembly provider from the parent container.
return container.GetRequiredService<IAssemblyProvider>();
});
// Register the compilation service in the isolated container.
services.AddScoped(provider => {
var accessor = provider.GetRequiredService<IHttpContextAccessor>();
@ -147,5 +142,20 @@ namespace Microsoft.AspNetCore.Builder {
controller.ControllerName = "OpenIddict";
}
}
private class OpenIddictPart : ApplicationPart, IApplicationPartTypeProvider {
public OpenIddictPart(OpenIddictConfiguration configuration) {
Types = new[] {
typeof(OpenIddictController<,>)
.MakeGenericType(configuration.UserType,
configuration.ApplicationType)
.GetTypeInfo()
};
}
public override string Name { get; } = "OpenIddict.Mvc";
public IEnumerable<TypeInfo> Types { get; }
}
}
}
Loading…
Cancel
Save