how to remove app.config in application code

995 Views Asked by At

I am writing a Dll project in which I am using EnterpriseLibrary.Caching.NetCore for in memory caching. This package require a app.config. Now when I call this DLL in my console application, I am bound to add app.config in my console application also. So I need to remove app.config from my console application.

1

There are 1 best solutions below

0
Aloene On BEST ANSWER

I think you can programmatically initialize the Enterprise Library Caching block by manually setting the Enterprise library container (IServiceLoccator) from a customized configuration. Thus, the application config file should not be read. For example :

var configSource = new DictionaryConfigurationSource();
var cacheSettings = new CacheManagerSettings();

configSource.Add(CacheManagerSettings.SectionName, cacheSettings);
var storageConfig = new CacheStorageData("NullBackingStore", typeof(NullBackingStore));
cacheSettings.BackingStores.Add(storageConfig);

var cacheManagerData = new CacheManagerData(
    "Cache Manager",
    60,
    1000,
    10,
    storageConfig.Name);
cacheSettings.CacheManagers.Add(cacheManagerData);
cacheSettings.DefaultCacheManager = "Cache Manager";
cacheSettings.DefaultCacheManager = cacheManagerData.Name;

EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);

EDIT: Note I have already used this kind of code for Enterprise Library on .NET Framework but I guess it should be the same on .Net core.