The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SubdomainRouteExtension.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.AspNetCore.Routing;
  3. using Microsoft.Extensions.DependencyInjection;
  4. using Microsoft.Extensions.Configuration;
  5. using System.Collections.Generic;
  6. namespace Teknik.Utilities
  7. {
  8. public static class SubdomainRouteExtension
  9. {
  10. public static SubdomainRoute MapSubdomainRoute(this IRouteBuilder routeBuilder, string name, List<string> subDomains, List<string> domains, string template, object defaults)
  11. {
  12. return MapSubdomainRoute(routeBuilder, name, subDomains, domains, template, defaults, new { }, new { });
  13. }
  14. public static SubdomainRoute MapSubdomainRoute(this IRouteBuilder routeBuilder, string name, List<string> subDomains, List<string> domains, string template, object defaults, object constraints)
  15. {
  16. return MapSubdomainRoute(routeBuilder, name, subDomains, domains, template, defaults, constraints, new { });
  17. }
  18. public static SubdomainRoute MapSubdomainRoute(this IRouteBuilder routeBuilder, string name, List<string> subDomains, List<string> domains, string template, object defaults, object constraints, object dataTokens)
  19. {
  20. var inlineConstraintResolver = routeBuilder.ServiceProvider.GetRequiredService<IInlineConstraintResolver>();
  21. SubdomainRoute route = new SubdomainRoute(
  22. subDomains,
  23. domains,
  24. routeBuilder.DefaultHandler,
  25. name,
  26. template,
  27. new RouteValueDictionary(defaults),
  28. new RouteValueDictionary(constraints),
  29. new RouteValueDictionary(dataTokens),
  30. inlineConstraintResolver);
  31. routeBuilder.Routes.Add(route);
  32. return route;
  33. }
  34. }
  35. }