public static IServiceCollection AddMiruUrls( this IServiceCollection services, Action <UrlOptions> options = null) { var routesInfo = new Dictionary <string, ModelToUrlMap>(); var convention = new MiruRoutingDiscoverer(routesInfo); services.AddSingleton <IActionContextAccessor, ActionContextAccessor>(); services.AddScoped(x => { var actionContext = x.GetRequiredService <IActionContextAccessor>().ActionContext; var factory = x.GetRequiredService <IUrlHelperFactory>(); return(factory.GetUrlHelper(actionContext)); }); services.AddSingleton <UrlLookup>(); services.AddSingleton <IUrlMaps, DefaultUrlMaps>(); services.AddSingleton(convention); services.Configure <MvcOptions>(x => x.Conventions.Add(convention)); if (options != null) { services.Configure(options); } services.AddSingleton(x => x.GetRequiredService <IOptions <UrlOptions> >().Value); services.AddSingleton(new QueryStringConfig()); return(services); }
public DefaultUrlMaps(LinkGenerator linkGenerator, MiruRoutingDiscoverer routings) { _linkGenerator = linkGenerator; _routings = routings; }