Enterprise Library for Silverlight– A Quick Start Guide
Here is a quick guide for setting up EntLib with your solution with a bit of problem solving. If you want to be able to configure your EntLib blocks from visual studio using the configuration console then you will have to make sure you install the following bits in the correct order
Otherwise you will end up with missing SL integration in the configuration console.
If the configuration console does not open and you get the following error:
“Error launching the configuration console. Could not locate the Enterprise Library binaries required to launch the configuration console. Either use NuGet to add references to the application blocks or set a value for the Enterprise Library binaries paths” property on the solution to indicate the location of the binaries.”
Then add the following to your solution file (or use NuGet instead):
GlobalSection(ExtensibilityGlobals) = postSolution EnterpriseLibraryConfigurationToolBinariesPath = C:\Program Files\Microsoft Enterprise Library 5.0\Bin EndGlobalSection
Afterwards you will have to add a config file to your project (the main silverlight project is good enough) and be able to right click it and configure it using the configuration console
You have several option to load the configuration to the EnterpirseLibraryContainer:
- Loading the XAML configuration from the server
- Embedding the XAML configuration in the XAP
unlike the above MSDN documentation suggest you have to set the XAML as “Embedded Resource” and not “Resource” or “Page” if you want to load the file as XAML. You then can call
to see what your resource is called inside the returned list (it’s the napespace of your solution + the path to the resource file). Then you can use it to load your cache like so
string xaml; using (Stream s = this.GetType().Assembly.GetManifestResourceStream("YourSolutionNamepsace.EntLib.xaml")) using (StreamReader sr = new StreamReader(s)) xaml = sr.ReadToEnd(); var configDictionary = (IDictionary)XamlReader.Load(xaml); var configSource = DictionaryConfigurationSource.FromDictionary(configDictionary); EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource); Microsoft.Practices.EnterpriseLibrary.Caching.Runtime.Caching.ObjectCache cache1 = EnterpriseLibraryContainer.Current.GetInstance
Don’t forget to add a reference to the “Microsoft.Practices.EnterpriseLibrary.Common.Silverlight.dll” + the application blocks you are using.
From here on, it should be basic settings and usage with the container.