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();
 }
        /// <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);
            });
        }
		public RazorViewServiceConfiguration(Registration<IRazorViewLoader> razorViewLoaderRegistration)
		{
			if (razorViewLoaderRegistration == null)
				throw new ArgumentNullException(nameof(razorViewLoaderRegistration));

			RazorViewLoader = razorViewLoaderRegistration;
			CompilerServiceFactory = new DefaultCompilerServiceFactory();
			EncodedStringFactory = new HtmlEncodedStringFactory();
			CachingProvider = new DefaultCachingProvider();
			Namespaces = new HashSet<string>()
			{
				"System",
				"System.Collections.Generic",
				"System.Linq"
			};
			RazorEngineConfigurationSection configuration = RazorEngineConfigurationSection.GetConfiguration();
			Language = configuration?.DefaultLanguage ?? Language.CSharp;
		}
        public ServiceFactory(Registration<IUserService> userService,
            StoreSettings storeSettings)
        {
            var client = new MongoClient(MongoClientSettings(storeSettings.ConnectionString));
            IMongoDatabase db = client.GetDatabase(storeSettings.Database);
            Register(new Registration<IMongoDatabase>(db));
            Register(new Registration<StoreSettings>(storeSettings));
            UserService = userService;
            ClientStore = new Registration<IClientStore>(typeof(ClientStore));
            ScopeStore = new Registration<IScopeStore>(typeof(ScopeStore));
            ConsentStore = new Registration<IConsentStore>(typeof (ConsentStore));
            
            AuthorizationCodeStore = new Registration<IAuthorizationCodeStore>(typeof(AuthorizationCodeStore));

            RefreshTokenStore = new Registration<IRefreshTokenStore>(typeof (RefreshTokenStore));
            TokenHandleStore = new Registration<ITokenHandleStore>(typeof (TokenHandleStore));
            Register(new Registration<ClientSerializer>(typeof(ClientSerializer)));
        }
 /// <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);
 }
 public void RegisterType_SetsTypeOnRegistration()
 {
     var result = new Registration<object>(typeof(string));
     result.Type.Should().Be(typeof(string));
 }
 public ServiceFactory(Registration<IUserService> userService)
     : this(userService, StoreSettings.DefaultSettings())
 {
 }