// Review: Need UseDefaultSubkey parameter? public static IServiceCollection AddAuthorization([NotNull] this IServiceCollection services, IConfiguration config = null, Action <AuthorizationOptions> configureOptions = null) { var describe = new ServiceDescriber(config); services.AddOptions(config); services.TryAdd(describe.Transient <IAuthorizationService, DefaultAuthorizationService>()); services.Add(describe.Transient <IAuthorizationHandler, ClaimsAuthorizationHandler>()); services.Add(describe.Transient <IAuthorizationHandler, DenyAnonymousAuthorizationHandler>()); services.Add(describe.Transient <IAuthorizationHandler, PassThroughAuthorizationHandler>()); if (configureOptions != null) { services.Configure(configureOptions); } return(services); }
public void DescriberDoesNotBlowUpWithNullConfiguration() { var describer = new ServiceDescriber(null); // Act describer.Transient <IFakeService, FakeService>(); }
public static IServiceCollection AddSignalR(this IServiceCollection services, IConfiguration configuration, Action <SignalROptions> configureOptions = null) { var describe = new ServiceDescriber(configuration); // Dependencies services.AddOptions(configuration); services.AddDataProtection(configuration); // SignalR services services.TryAdd(describe.Singleton <IMessageBus, MessageBus>()); services.TryAdd(describe.Singleton <IMemoryPool, MemoryPool>()); services.TryAdd(describe.Singleton <IStringMinifier, StringMinifier>()); services.TryAdd(describe.Singleton <ITransportManager, TransportManager>()); services.TryAdd(describe.Singleton <ITransportHeartbeat, TransportHeartbeat>()); services.TryAdd(describe.Singleton <IConnectionManager, ConnectionManager>()); services.TryAdd(describe.Singleton <IAckHandler, AckHandler>()); services.TryAdd(describe.Singleton <AckSubscriber, AckSubscriber>()); services.TryAdd(describe.Singleton <IAssemblyLocator, DefaultAssemblyLocator>()); services.TryAdd(describe.Singleton <IHubManager, DefaultHubManager>()); services.TryAdd(describe.Singleton <IMethodDescriptorProvider, ReflectedMethodDescriptorProvider>()); services.TryAdd(describe.Singleton <IHubDescriptorProvider, ReflectedHubDescriptorProvider>()); services.TryAdd(describe.Singleton <IPerformanceCounterManager, PerformanceCounterManager>()); services.TryAdd(describe.Singleton <JsonSerializer, JsonSerializer>()); services.TryAdd(describe.Singleton <IUserIdProvider, PrincipalUserIdProvider>()); services.TryAdd(describe.Singleton <IParameterResolver, DefaultParameterResolver>()); services.TryAdd(describe.Singleton <IHubActivator, DefaultHubActivator>()); services.TryAdd(describe.Singleton <IJavaScriptProxyGenerator, DefaultJavaScriptProxyGenerator>()); services.TryAdd(describe.Singleton <IJavaScriptMinifier, NullJavaScriptMinifier>()); services.TryAdd(describe.Singleton <IHubRequestParser, HubRequestParser>()); services.TryAdd(describe.Singleton <IHubPipelineInvoker, HubPipeline>()); services.TryAdd(describe.Singleton(typeof(IPersistentConnectionContext <>), typeof(PersistentConnectionContextService <>))); services.TryAdd(describe.Singleton(typeof(IHubContext <>), typeof(HubContextService <>))); services.TryAdd(describe.Singleton(typeof(IHubContext <,>), typeof(HubContextService <,>))); // TODO: Just use the new IDataProtectionProvider abstraction directly here services.TryAdd(describe.Singleton <IProtectedData, DataProtectionProviderProtectedData>()); // Setup the default SignalR options services.TryAdd(describe.Transient <IConfigureOptions <SignalROptions>, SignalROptionsSetup>()); if (configuration != null) { services.Configure <SignalROptions>(configuration); } if (configureOptions != null) { services.ConfigureSignalR(configureOptions); } return(services); }
public static IServiceCollection AddHosting(this IServiceCollection services, IConfiguration configuration = null) { var describer = new ServiceDescriber(configuration); services.TryAdd(describer.Transient <IHostingEngine, HostingEngine>()); services.TryAdd(describer.Transient <IServerManager, ServerManager>()); services.TryAdd(describer.Transient <IStartupManager, StartupManager>()); services.TryAdd(describer.Transient <IStartupLoaderProvider, StartupLoaderProvider>()); services.TryAdd(describer.Transient <IApplicationBuilderFactory, ApplicationBuilderFactory>()); services.TryAdd(describer.Transient <IHttpContextFactory, HttpContextFactory>()); services.TryAdd(describer.Instance <IApplicationLifetime>(new ApplicationLifetime())); services.AddTypeActivator(configuration); // TODO: Do we expect this to be provide by the runtime eventually? services.AddLogging(configuration); // REVIEW: okay to use existing hosting environment/httpcontext if specified? services.TryAdd(describer.Singleton <IHostingEnvironment, HostingEnvironment>()); // TODO: Remove this once we have IHttpContextAccessor services.AddContextAccessor(configuration); // REVIEW: don't try add because we pull out IEnumerable<IConfigureHostingEnvironment>? services.AddInstance <IConfigureHostingEnvironment>(new ConfigureHostingEnvironment(configuration)); return(services); }
public static IdentityBuilder AddIdentity <TUser, TRole>( this IServiceCollection services, IConfiguration identityConfig = null, Action <IdentityOptions> configureOptions = null, bool useDefaultSubKey = true) where TUser : class where TRole : class { if (identityConfig != null) { if (useDefaultSubKey) { identityConfig = identityConfig.GetSubKey("identity"); } services.Configure <IdentityOptions>(identityConfig); } var describe = new ServiceDescriber(identityConfig); // Services used by identity services.AddOptions(identityConfig); services.AddDataProtection(identityConfig); // Identity services services.TryAdd(describe.Transient <IUserValidator <TUser>, UserValidator <TUser> >()); services.TryAdd(describe.Transient <IPasswordValidator <TUser>, PasswordValidator <TUser> >()); services.TryAdd(describe.Transient <IPasswordHasher <TUser>, PasswordHasher <TUser> >()); services.TryAdd(describe.Transient <ILookupNormalizer, UpperInvariantLookupNormalizer>()); services.TryAdd(describe.Transient <IRoleValidator <TRole>, RoleValidator <TRole> >()); // No interface for the error describer so we can add errors without rev'ing the interface services.TryAdd(describe.Transient <IdentityErrorDescriber, IdentityErrorDescriber>()); services.TryAdd(describe.Scoped <ISecurityStampValidator, SecurityStampValidator <TUser> >()); services.TryAdd(describe.Scoped <IClaimsIdentityFactory <TUser>, ClaimsIdentityFactory <TUser, TRole> >()); services.TryAdd(describe.Scoped <UserManager <TUser>, UserManager <TUser> >()); services.TryAdd(describe.Scoped <SignInManager <TUser>, SignInManager <TUser> >()); services.TryAdd(describe.Scoped <RoleManager <TRole>, RoleManager <TRole> >()); if (configureOptions != null) { services.ConfigureIdentity(configureOptions); } services.Configure <ExternalAuthenticationOptions>(options => { options.SignInAsAuthenticationType = IdentityOptions.ExternalCookieAuthenticationType; }); // Configure all of the cookie middlewares services.Configure <CookieAuthenticationOptions>(options => { options.AuthenticationType = IdentityOptions.ApplicationCookieAuthenticationType; options.LoginPath = new PathString("/Account/Login"); options.Notifications = new CookieAuthenticationNotifications { OnValidateIdentity = SecurityStampValidator.ValidateIdentityAsync }; }, IdentityOptions.ApplicationCookieAuthenticationType); services.Configure <CookieAuthenticationOptions>(options => { options.AuthenticationType = IdentityOptions.ExternalCookieAuthenticationType; options.AuthenticationMode = AuthenticationMode.Passive; options.CookieName = IdentityOptions.ExternalCookieAuthenticationType; options.ExpireTimeSpan = TimeSpan.FromMinutes(5); }, IdentityOptions.ExternalCookieAuthenticationType); services.Configure <CookieAuthenticationOptions>(options => { options.AuthenticationType = IdentityOptions.TwoFactorRememberMeCookieAuthenticationType; options.AuthenticationMode = AuthenticationMode.Passive; options.CookieName = IdentityOptions.TwoFactorRememberMeCookieAuthenticationType; }, IdentityOptions.TwoFactorRememberMeCookieAuthenticationType); services.Configure <CookieAuthenticationOptions>(options => { options.AuthenticationType = IdentityOptions.TwoFactorUserIdCookieAuthenticationType; options.AuthenticationMode = AuthenticationMode.Passive; options.CookieName = IdentityOptions.TwoFactorUserIdCookieAuthenticationType; options.ExpireTimeSpan = TimeSpan.FromMinutes(5); }, IdentityOptions.TwoFactorUserIdCookieAuthenticationType); return(new IdentityBuilder(typeof(TUser), typeof(TRole), services)); }
public IServiceCollection AddTransient(Type service, Type implementationType) { Add(_describe.Transient(service, implementationType)); return(this); }