Ejemplo n.º 1
0
 // Copy constructor.
 internal RedisTempDataProviderOptions(RedisTempDataProviderOptions other)
 {
     KeyPrefix    = other.KeyPrefix;
     KeySeparator = other.KeySeparator;
     UserProvider = other.UserProvider;
     Serializer   = other.Serializer;
 }
 // Copy constructor.
 internal RedisTempDataProviderOptions(RedisTempDataProviderOptions other)
 {
     KeyPrefix = other.KeyPrefix;
     KeySeparator = other.KeySeparator;
     UserProvider = other.UserProvider;
     Serializer = other.Serializer;
 }
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            kernel.Bind<ConnectionMultiplexer>()
                .ToMethod(ctx => ConnectionMultiplexer.Connect("localhost"))
                .InSingletonScope();

            kernel.Bind<IDatabase>()
                .ToMethod(ctx => ctx.Kernel.Get<ConnectionMultiplexer>().GetDatabase(0))
                .InRequestScope();

            // Besure to override CreateTempDataProvider so that DependencyResolver
            // behaves as expected. See this bug in MVC >= 4:
            // https://aspnetwebstack.codeplex.com/workitem/1692
            kernel.Bind<ITempDataProvider>()
                .ToMethod(ctx =>
                {
                    var options = new RedisTempDataProviderOptions()
                    {
                        KeyPrefix = "MyTempData",
                        KeySeparator = "/",
                        // Serializer = new CustomTempDataSerializer(),
                        // UserProvider = new CustomUserProvider()
                    };

                    return new RedisTempDataProvider(options, ctx.Kernel.Get<IDatabase>());
                })
                .InRequestScope();
        }        
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            // Ideally you'd use PooledClientManager in production!
            kernel.Bind<IRedisClientsManager>()
                .To<BasicRedisClientManager>()
                .InSingletonScope();

            kernel.Bind<IRedisClient>()
                .ToMethod(ctx => ctx.Kernel.Get<IRedisClientsManager>().GetClient())
                .InRequestScope();

            // Besure to override CreateTempDataProvider so that DependencyResolver
            // behaves as expected. See this bug in MVC:
            // https://aspnetwebstack.codeplex.com/workitem/1692
            kernel.Bind<ITempDataProvider>()
                .ToMethod(ctx =>
                {
                    var options = new RedisTempDataProviderOptions()
                    {
                        KeyPrefix = "MyTempData",
                        KeySeparator = "/",
                        // Serializer = new CustomTempDataSerializer(),
                        // UserProvider = new CustomUserProvider()
                    };

                    return new RedisTempDataProvider(options, ctx.Kernel.Get<IRedisClient>());
                })
                .InRequestScope();
        }        
        public RedisTempDataProvider(RedisTempDataProviderOptions options, IDatabase redis)
        {
            if (options == null) throw new ArgumentNullException(nameof(options));
            if (redis == null) throw new ArgumentNullException(nameof(redis));

            // Copy so that references can't be modified outside of this class.
            this.options = new RedisTempDataProviderOptions(options);
            this.redis = redis;
        }
Ejemplo n.º 6
0
        public RedisTempDataProvider(RedisTempDataProviderOptions options, IDatabase redis)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (redis == null)
            {
                throw new ArgumentNullException(nameof(redis));
            }

            // Copy so that references can't be modified outside of this class.
            this.options = new RedisTempDataProviderOptions(options);
            this.redis   = redis;
        }