Giter Club home page Giter Club logo

Comments (4)

MichaCo avatar MichaCo commented on May 26, 2024

What do you exactly mean with "support generic instance"?
If you don't want to configure each type, use "object". there are overloads everywhere to create non typed instances...
If you want to use DI to inject an instance per type, see #20

Cachemanager actually handles retries for you if you use Redis. you can controll the connection timeout in the redis configuration and the cache manager itself has properties for retry timeout and max retries.
That being said, do you have a reproduceable configuration/scenario you are using where this is not working? Please post it here so that I can test it.
Thanks

from cachemanager.

18098924759 avatar 18098924759 commented on May 26, 2024

I'm use autofac,but I don't know how to register an instance in bulk,Can you provide an example for me,thank you !

Here is my code:
//var intCache = CacheFactory.FromConfiguration("intCache", cfg);
//var stringCache = CacheFactory.FromConfiguration("stringCache", cfg);
//var objectCache = CacheFactory.FromConfiguration("objectCache", cfg);

//builder.RegisterInstance(intCache);
//builder.RegisterInstance(stringCache);
//builder.RegisterInstance(objectCache);
//builder.RegisterInstance(cache);

var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

from cachemanager.

MichaCo avatar MichaCo commented on May 26, 2024

Well, autofac also has a way to register open generics, something like this should work:

var cacheConfig = ConfigurationBuilder.BuildConfiguration(...);

var builder = new ContainerBuilder();
builder
    .RegisterGeneric(typeof(BaseCacheManager<>))
    .WithParameters(new[]
    {
        new TypedParameter(typeof(string), "myCache"),
        new TypedParameter(typeof(CacheManagerConfiguration), cacheConfig)
    })
    .As(typeof(ICacheManager<>))
    .SingleInstance();

Don't forget the SingleInstance() call to make each cache manager instance the container creates, a singleton.

from cachemanager.

jrt324 avatar jrt324 commented on May 26, 2024

In version 0.9.3 should be:

 builder.RegisterGeneric(typeof(BaseCacheManager<>))
                .WithParameters(new[]
                {
                    new TypedParameter(typeof(ICacheManagerConfiguration), cacheConfig)
                })
                .As(typeof(ICacheManager<>))
                .SingleInstance(); 

from cachemanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.