Lazy Loading DLL's with MEF?

First, you are trying to import objects into a static property. This is not supported by MEF: MEF composes objects not classes If you want to initialize static properties, you have to do it manually like this: DllList = container.GetExports() Now about lazy loading: DirectoryCatalog creates a AssemblyCatalog for each assembly in the directory. The AssemblyCatalog implementation in MEF will enumerate all types in the assembly as soon as AssemblyCatalog.

Parts is called, which will happen when you pull an export from the container. This means that the assembly is loaded even before MEF has determined that it contains a part that it actually needs In order to truly have lazy loading of assemblies, the information about which parts are available in those assemblies would need to be cached somewhere. MEF currently does not have such a built-in cache mechanism out of the box.

However, there is a ComposablePartCatalogAssemblyCache implementation in the samples included with the MEF source code at codeplex The only thing that Lazy.

First, you are trying to import objects into a static property. This is not supported by MEF: MEF composes objects, not classes. If you want to initialize static properties, you have to do it manually like this: DllList = container.GetExports(); Now about lazy loading: DirectoryCatalog creates a AssemblyCatalog for each assembly in the directory.

The AssemblyCatalog implementation in MEF will enumerate all types in the assembly as soon as AssemblyCatalog. Parts is called, which will happen when you pull an export from the container. This means that the assembly is loaded even before MEF has determined that it contains a part that it actually needs.In order to truly have lazy loading of assemblies, the information about which parts are available in those assemblies would need to be cached somewhere.

MEF currently does not have such a built-in cache mechanism out of the box. However, there is a ComposablePartCatalogAssemblyCache implementation in the samples included with the MEF source code at codeplex. The only thing that Lazy does is postpone the moment that the constructor of the part is called.

This can already speed up things but it won't postpone the loading of assemblies.

The great thing about MEF is (by default) you don't initialize the object; MEF will match up any declared Export that match up your import and will then MEF inits them for you. If your dependencies themselves have dependencies, MEF will continue down the chain until your entire graph is resolved. Using Lazy (as opposed to T) just means that instantiation will be delayed until you access that dependency.

If, perhaps, you are debugging, and you aren't seeing when that dependency is initialized, you'll need to access the Value property in order to kick off the instantiation. There are some big differences between MEF and most other IoC containers (as MEF is focused just on extensibility/composition), but it's similar to how an IoC container will, after a type has been registered, will instantiate a dependency when you resolve something. If you are curious about how you can change some of the instantiation behavior, there's some detail on creation policies here: mef.codeplex.com/wikipage?title=Parts%20....

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions