Caching Block in a library

Topics: Caching Application Block
Jul 4, 2007 at 5:52 AM

I am planning to develop a C# project of library type.
As a library does not have a app.config neither a web.config file, how and where can i store the configuration necessary to use the application block in my library?

Or can it only be defined in the web.config or app.config of the client application using my library?

Thanks in advance for any help,

Francois Malgreve
Jul 4, 2007 at 2:23 PM
Hi Francois,

You could provide your own configuration file, let's say "mylib.config", and access it through a FileConfigurationSource for that file. However some functionality will not be available for you, like the "static factories" such as CacheFactory which assume the app's configuration is used, and you'd need to deal with the lifetime of the objects yourself.

This shows an example.

IConfigurationSource source = new FileConfigurationSource("mylib.config"); // the name should be stored somewhere safe, probably config
CacheManagerFactory factory = new CacheManagerFactory(source); // keep a reference to this factory globally; you need the same factory to get the same instance

CacheManager cache = factory.CreateDefault();

Hope this helps,