http://stackoverflow.com/questions/16943121/defining-scope-in-mef-with-compositionscopedefinition
http://stackoverflow.com/questions/16943121/defining-scope-in-mef-with-compositionscopedefinition
public class Bootstrapper : UnityBootstrapper
{
protected override void ConfigureContainer()
{
Container.RegisterType<IShell, Shell>(new ContainerControlledLifetimeManager());
base.ConfigureContainer();
}
protected override DependencyObject CreateShell()
{
var shell = Container.Resolve<IShell>();
return shell as DependencyObject;
}
#region Private Properties
private IEventAggregator EventAggregator
{
get { return Container.Resolve<IEventAggregator>(); }
}
#endregion
protected override void InitializeModules()
{
IModule splashModule = Container.Resolve<Splash.Module>();
splashModule.Initialize();
EventAggregator.GetEvent<MessageUpdateEvent>().Publish(new MessageUpdateEvent {Message = "Module1"});
Thread.Sleep(2000); //simulate long loading of the module
IModule customersModule = Container.Resolve<Module1.Module>();
customersModule.Initialize();
EventAggregator.GetEvent<MessageUpdateEvent>().Publish(new MessageUpdateEvent { Message = "Module2" });
Thread.Sleep(2000); //simulate long loading of the module
IModule locationModule = Container.Resolve<Module2.Module>();
locationModule.Initialize();
EventAggregator.GetEvent<MessageUpdateEvent>().Publish(new MessageUpdateEvent { Message = "Module3" });
Thread.Sleep(2000); //simulate long loading of the module
IModule ordersModule = Container.Resolve<Module3.Module>();
ordersModule.Initialize();
}
}
Having trouble coming up with a solution. I have large amounts of data to load and need this logic. I tried using the code from this project "Improving perceived WPF app startup performance with MEF and a Splash Screen", but also having trouble getting imports to work.IModuleManager manager = ServiceLocator.Current.GetInstance<IModuleManager>();
manager.LoadModule("ModuleA");
hi mrsquish,
I am not very familiar with nhibernate, but the problem that you are running into would seem to be solvable by using the CompositionScopeDefinition class. At a high level . Composition Scope Definition allows you a mechanism to define scopes in which things are shared. Take a look at this article which talks about Composition Scope Definition and let us know if that works for you
cheers
public interface IRequireSession
{
ISession Session { get; set; }
}
And is implemented in a Form base class : public class DataForm : Form, IRequireSession
{
private ISession _session;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Import()]
public ISession Session
{
get { return _session; }
set {
_session = value;
SetSession(this.Controls);
}
}
private void SetSession(Control.ControlCollection controls)
{
foreach (Control control in controls)
{
if (control is IRequireSession)
((IRequireSession)control).Session = _session;
SetSession(control.Controls);
}
}
}
This means that I can derive my normal forms from DataForm and get the session passed through to any user controls that implement IRequireSession. Although, I've got a funny feeling that MEF doesn't support attributes on base classes. . I guess I'll find out soon enough.