public AdminServiceRegistry() { AdminService = new Registration<IAdminService>(typeof(AdminService)); TokenCleanupService = new Registration<ICleanupExpiredTokens>(typeof(CleanupExpiredTokens)); }
public void RegisterSingleton_Instance_ReturnsSingleton() { object theSingleton = new object(); var reg = new Registration<object>((object)theSingleton); var result = reg.Instance; result.Should().BeSameAs(theSingleton); }
public void RegisterFactory_FactoryInvokesFunc() { var wasCalled = false; Func<IDependencyResolver, object> f = (resolver) => { wasCalled = true; return new object(); }; var reg = new Registration<object>(f); var result = reg.Factory(null); wasCalled.Should().BeTrue(); }
private static void Register(this ContainerBuilder builder, Registration registration) { if (registration.ImplementationType != null) { builder.RegisterType(registration.ImplementationType).As(registration.InterfaceType); } else if (registration.ImplementationFactory != null) { builder.Register(ctx => registration.ImplementationFactory()).As(registration.InterfaceType); } else { var message = "No type or factory found on registration " + registration.GetType().FullName; Logger.Error(message); throw new InvalidOperationException(message); } }
/// <summary> /// Configures the provided cache in the dependency injection system as a decorator for the scope store. /// </summary> /// <param name="factory">The factory.</param> /// <param name="cacheRegistration">The cache registration.</param> /// <exception cref="System.ArgumentNullException"> /// factory /// or /// cacheRegistration /// or /// ScopeStore needs to be configured on the factory /// </exception> public static void ConfigureScopeStoreCache(this IdentityServerServiceFactory factory, Registration<ICache<IEnumerable<Scope>>> cacheRegistration) { if (factory == null) throw new ArgumentNullException("factory"); if (cacheRegistration == null) throw new ArgumentNullException("cacheRegistration"); if (factory.ScopeStore == null) throw new ArgumentNullException("ScopeStore needs to be configured on the factory"); factory.Register(new Registration<ICache<IEnumerable<Scope>>>(cacheRegistration, CachingRegistrationName)); factory.Register(new Registration<IScopeStore>(factory.ScopeStore, InnerRegistrationName)); factory.ScopeStore = new Registration<IScopeStore>(resolver => { var inner = resolver.Resolve<IScopeStore>(InnerRegistrationName); var cache = resolver.Resolve<ICache<IEnumerable<Scope>>>(CachingRegistrationName); return new CachingScopeStore(inner, cache); }); }
private static void Register(this ContainerBuilder builder, Registration registration, string name = null) { if (registration.Instance != null) { var reg = builder.Register(ctx => registration.Instance).SingleInstance(); if (name != null) { reg.Named(name, registration.DependencyType); } else { reg.As(registration.DependencyType); } } else if (registration.Type != null) { var reg = builder.RegisterType(registration.Type); if (name != null) { reg.Named(name, registration.DependencyType); } else { reg.As(registration.DependencyType); } } else if (registration.Factory != null) { var reg = builder.Register(ctx => registration.Factory(new AutofacDependencyResolver(ctx))); if (name != null) { reg.Named(name, registration.DependencyType); } else { reg.As(registration.DependencyType); } } else { var message = "No type or factory found on registration " + registration.GetType().FullName; Logger.Error(message); throw new InvalidOperationException(message); } }
public void RegisterType_SetsTypeOnRegistration() { var result = new Registration<object>(typeof(string)); result.Type.Should().Be(typeof(string)); }
/// <summary> /// Configures the default cache for the scope store. /// </summary> /// <param name="factory">The factory.</param> public static void ConfigureScopeStoreCache(this IdentityServerServiceFactory factory) { var cache = new DefaultCache<IEnumerable<Scope>>(); var cacheRegistration = new Registration<ICache<IEnumerable<Scope>>>(cache); factory.ConfigureScopeStoreCache(cacheRegistration); }
/// <summary> /// Configures an in-memory, time-based cache for the user service store. /// </summary> /// <param name="factory">The factory.</param> /// <param name="cacheDuration">Duration of the cache.</param> public static void ConfigureUserServiceCache(this IdentityServerServiceFactory factory, TimeSpan cacheDuration) { var cache = new DefaultCache<IEnumerable<Claim>>(cacheDuration); var cacheRegistration = new Registration<ICache<IEnumerable<Claim>>>(cache); factory.ConfigureUserServiceCache(cacheRegistration); }
/// <summary> /// Configures the default cache for the client store. /// </summary> /// <param name="factory">The factory.</param> public static void ConfigureClientStoreCache(this IdentityServerServiceFactory factory) { var cache = new DefaultCache<Client>(); var cacheRegistration = new Registration<ICache<Client>>(cache); factory.ConfigureClientStoreCache(cacheRegistration); }