public static IMultiTenantKitBuilder AddDefaultDomainResolverService(this IMultiTenantKitBuilder builder, string domainTemplate)
        {
            builder.AddDefaultDomainResolverService(options =>
            {
                options.DomainTemplate = domainTemplate;
            });

            return(builder);
        }
        public static IMultiTenantKitBuilder AddDefaultClaimResolverService(this IMultiTenantKitBuilder builder, string claimName)
        {
            builder.AddDefaultClaimResolverService(options =>
            {
                options.ClaimName = claimName;
            });

            return(builder);
        }
        public static IMultiTenantKitBuilder AddDefaultRouteResolverService(this IMultiTenantKitBuilder builder, string routeSegmentName)
        {
            builder.AddDefaultRouteResolverService(options =>
            {
                options.RouteSegmentName = routeSegmentName;
            });

            return(builder);
        }
        public static IMultiTenantKitBuilder AddDefaultTenantProviderService(this IMultiTenantKitBuilder builder)
        {
            Type ITenantProviderType = typeof(ITenantProvider <>).MakeGenericType(builder.TenantType);
            Type STenantProviderType = typeof(TenantProviderService <>).MakeGenericType(builder.TenantType);

            builder.Services.TryAddScoped(ITenantProviderType, STenantProviderType);

            return(builder);
        }
        public static IMultiTenantKitBuilder AddDefaultTenantInfoService(this IMultiTenantKitBuilder builder)
        {
            Type ITenantInfoType = typeof(ITenantInfoService <>).MakeGenericType(builder.TenantType);
            Type STenantInfoType = typeof(TenantInfoService <>).MakeGenericType(builder.TenantType);

            builder.Services.TryAddTransient(ITenantInfoType, STenantInfoType);

            return(builder);
        }
        public static IMultiTenantKitBuilder AddInMemoryTenantMappingsStore(this IMultiTenantKitBuilder builder, IConfigurationSection configurationSection)
        {
            Type tenantMappingListType = typeof(List <>).MakeGenericType(builder.TenantMappingType);

            object tenantMappings = Activator.CreateInstance(tenantMappingListType);

            configurationSection.Bind(tenantMappings);

            return(builder.AddInMemoryTenantMappingsStore((IEnumerable <ITenantMapping>)tenantMappings));
        }
        public static IMultiTenantKitBuilder AddDefaultDomainResolverService(this IMultiTenantKitBuilder builder, Action <HostResolverOptions> configureOptions)
        {
            if (!builder.Services.Any(x => x.ServiceType == typeof(IConfigureOptions <HostResolverOptions>)))
            {
                builder.Services.Configure(configureOptions);
            }

            builder.Services.TryAddTransient <ITenantResolverService, TenantHostResolverService>();

            return(builder);
        }
        public static IMultiTenantKitBuilder AddInMemoryTenantMappingsStore(this IMultiTenantKitBuilder builder, IEnumerable <ITenantMapping> tenantMappings)
        {
            Type ITenantMappingStoreType  = typeof(ITenantMappingStore <>).MakeGenericType(builder.TenantMappingType);
            Type STenantMappingsStoreType = typeof(InMemoryTenantMappingStore <>).MakeGenericType(builder.TenantMappingType);

            builder.Services.AddScoped(ITenantMappingStoreType, s =>
            {
                return(Activator.CreateInstance(STenantMappingsStoreType, tenantMappings));
            });

            return(builder);
        }
        public static IMultiTenantKitBuilder AddCustomTenantStore <TTenantStore>(this IMultiTenantKitBuilder builder)
            where TTenantStore : class
        {
            Type ICustomTenantStoreType = typeof(ITenantStore <>).MakeGenericType(builder.TenantType);
            Type SCustomTenantStoreType = typeof(TTenantStore);

            if (!ICustomTenantStoreType.GetTypeInfo().IsAssignableFrom(SCustomTenantStoreType.GetTypeInfo()))
            {
                throw new InvalidOperationException($"You must use a type that implements {ICustomTenantStoreType.ToString()}!");
            }

            builder.Services.AddTransient(ICustomTenantStoreType, SCustomTenantStoreType);

            return(builder);
        }
        public static IMultiTenantKitBuilder AddCustomTenantResolverService <TResolverService>(this IMultiTenantKitBuilder builder)
            where TResolverService : class, ITenantResolverService
        {
            builder.Services.AddTransient <ITenantResolverService, TResolverService>();

            return(builder);
        }
        public static IMultiTenantKitBuilder AddDefaultClaimResolverService(this IMultiTenantKitBuilder builder)
        {
            builder.AddDefaultClaimResolverService("TenantId");

            return(builder);
        }
        public static IMultiTenantKitBuilder AddDefaultDomainResolverService(this IMultiTenantKitBuilder builder)
        {
            builder.AddDefaultDomainResolverService("{0}.midomain.com");

            return(builder);
        }
        public static IMultiTenantKitBuilder AddDefaultRouteResolverService(this IMultiTenantKitBuilder builder)
        {
            builder.AddDefaultRouteResolverService("tenant");

            return(builder);
        }