Client Configuration without .config

Topics: User Forum
Jun 4, 2009 at 2:25 PM

Hi,

I'm trying to figure out how I can use the SharedCache client without an .exe.config.

As I said earlier my SharedCache application is a third part application plugin, it's distributed as a dll. I'm not able to edit the .exe.config and the .net framework does not consider .dll.config.

How can I configure SharedCache without the .exe.config support?

The ClientSettingElement Class is using ConfigurationElement directly and I'm not used to it.

thank you,

Samuel

Jun 8, 2009 at 7:23 PM

Hi,

The code below should do the trick (as a proof of concept, after that I could include it at the IndexusDistributionCache class code):

WebConfigurationFileMap fileMap = new WebConfigurationFileMap();
            fileMap.MachineConfigFilename =
                System.IO.Path.Combine(
                    System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location),
                    @"app.config");
            Configuration config = WebConfigurationManager.OpenMappedWebConfiguration(fileMap, "");
            IndexusProviderSection providerSection = (IndexusProviderSection)config.GetSection("indexusNetSharedCache");
            IndexusProviderCollection providerCollection = new IndexusProviderCollection();
            ProvidersHelper.InstantiateProviders(
                                                    providerSection.Providers,
                    providerCollection,
                    typeof(IndexusProviderBase)
                );

            IndexusProviderBase providerBase = providerCollection[providerSection.DefaultProvider];

But the config.GetSection("indexusNetSharedCache") is returning a System.Configuration.DefaultSection instead of a IndexusProviderSection instance.

 

Any help on this?

 

Thanks

Coordinator
Jun 8, 2009 at 8:32 PM

I hadn't to much time to think about this issue but the idea would be in general very intersting to configure server from remote. did you had a look at this thread: http://sharedcache.codeplex.com/Thread/View.aspx?ThreadId=45953 ?

the sample code i received I have uploaded to the following location: http://www.sharedcache.com/cms/Download/ConfigurationFactoryExample.zip

regards,

roni