Guest User

Untitled

a guest
Jun 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. services.AddMvcCore(setup =>
  2. {
  3. setup.Filters.Add(new AuthorizeFilter());
  4.  
  5. // Get all global filters
  6. foreach (var filter in GetInterfacesFromAssembly<IGlobalAsyncFilter>())
  7. setup.Filters.Add(new AsyncActionFilterProxy(filter, container));
  8. })
  9. .SetCompatibilityVersion(CompatibilityVersion.Latest)
  10. .AddFormatterMappings()
  11. .AddJsonFormatters()
  12. .AddCors()
  13. .AddAuthorization(o =>
  14. {
  15. o.DefaultPolicy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme)
  16. .RequireAuthenticatedUser()
  17. .Build();
  18. })
  19. .AddApplicationPart(GetModuleAssemblies());
  20.  
  21. /// <summary>
  22. /// Get any DLL that contains "ModularPortal.Modules.*.dll"
  23. /// </summary>
  24. private static IEnumerable<Assembly> GetModuleAssemblies()
  25. {
  26. string location = Assembly.GetEntryAssembly().Location;
  27. string path = Path.GetDirectoryName(location);
  28. DirectoryInfo directory = new DirectoryInfo(path);
  29.  
  30. FileInfo[] files = directory.GetFiles("ModularPortal.Module*.dll");
  31. foreach (FileInfo file in files)
  32. yield return Assembly.Load(file.Name.Replace(".dll", ""));
  33. }
  34.  
  35. [AllowAnonymous]
  36. public class Example1Controller : ControllerBase
  37. {
  38. readonly IMembership membership;
  39.  
  40. public Example1Controller(
  41. IMembership membership
  42. )
  43. {
  44. this.membership = membership;
  45. }
  46.  
  47. [HttpGet]
  48. public IActionResult Test()
  49. {
  50. return Ok("t1");
  51. }
  52. }
  53.  
  54. public interface IModule
  55. {
  56. string DisplayName { get; }
  57. string RouteName { get; }
  58.  
  59. void Configure(ModuleConfiguration config);
  60. }
  61.  
  62. public class Module : IModule
  63. {
  64. public string DisplayName => "Example Module";
  65.  
  66. public string RouteName => "Ex";
  67.  
  68. public void Configure(ModuleConfiguration config)
  69. {
  70. throw new NotImplementedException();
  71. }
  72. }
Add Comment
Please, Sign In to add comment