コード例 #1
0
        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);
        }
コード例 #2
0
 public DefaultUrlMaps(LinkGenerator linkGenerator, MiruRoutingDiscoverer routings)
 {
     _linkGenerator = linkGenerator;
     _routings      = routings;
 }