Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- services.AddMvcCore(setup =>
- {
- setup.Filters.Add(new AuthorizeFilter());
- // Get all global filters
- foreach (var filter in GetInterfacesFromAssembly<IGlobalAsyncFilter>())
- setup.Filters.Add(new AsyncActionFilterProxy(filter, container));
- })
- .SetCompatibilityVersion(CompatibilityVersion.Latest)
- .AddFormatterMappings()
- .AddJsonFormatters()
- .AddCors()
- .AddAuthorization(o =>
- {
- o.DefaultPolicy = new AuthorizationPolicyBuilder(JwtBearerDefaults.AuthenticationScheme)
- .RequireAuthenticatedUser()
- .Build();
- })
- .AddApplicationPart(GetModuleAssemblies());
- /// <summary>
- /// Get any DLL that contains "ModularPortal.Modules.*.dll"
- /// </summary>
- private static IEnumerable<Assembly> GetModuleAssemblies()
- {
- string location = Assembly.GetEntryAssembly().Location;
- string path = Path.GetDirectoryName(location);
- DirectoryInfo directory = new DirectoryInfo(path);
- FileInfo[] files = directory.GetFiles("ModularPortal.Module*.dll");
- foreach (FileInfo file in files)
- yield return Assembly.Load(file.Name.Replace(".dll", ""));
- }
- [AllowAnonymous]
- public class Example1Controller : ControllerBase
- {
- readonly IMembership membership;
- public Example1Controller(
- IMembership membership
- )
- {
- this.membership = membership;
- }
- [HttpGet]
- public IActionResult Test()
- {
- return Ok("t1");
- }
- }
- public interface IModule
- {
- string DisplayName { get; }
- string RouteName { get; }
- void Configure(ModuleConfiguration config);
- }
- public class Module : IModule
- {
- public string DisplayName => "Example Module";
- public string RouteName => "Ex";
- public void Configure(ModuleConfiguration config)
- {
- throw new NotImplementedException();
- }
- }
Add Comment
Please, Sign In to add comment