LMeyer
LMeyer

Reputation: 2631

How to get DirectoryModuleCatalog to work?

I am using Prism 4 and MEF for a WPF project. I have some DLL that needs to be loaded from a directory. These DLL implements IModule through IGame and are properly formed (or at least I think so) :

[Module(ModuleName = "SnakeModule")]
class SnakeModule : IGame
{
    public void Initialize()
    {
        Console.WriteLine("test");
    }

    public void StartGame()
    {
        throw new NotImplementedException();
    }

}

Currently, the main project is compiling but the module doesn't get initialized. I have trouble understanding how to setup my bootstrapper and the documentation isn't helping much since it doesn't have full example with a DirectoryModuleCatalog. The modularity quickstart isn't compiling either. Here is my bootstrapper :

class BootStrap : MefBootstrapper
    {

        protected override DependencyObject CreateShell()
        {
            return ServiceLocator.Current.GetInstance<Shell>();
        }

        protected override void InitializeShell()
        {
            Application.Current.MainWindow = (Window)this.Shell;
            Application.Current.MainWindow.Show();
        }

        protected override void ConfigureAggregateCatalog()
        {
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(BootStrap).Assembly));  
        }


        protected override IModuleCatalog CreateModuleCatalog()
        {

            DirectoryModuleCatalog catalog = new DirectoryModuleCatalog() { ModulePath = @"..\..\..\GameTestLib\bin\Debug" };
            return catalog;
        }

        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();
        }

    }

Paths for the DLLs are correct. To sum up, my question is : How should I setup my bootstrapper ?

Upvotes: 3

Views: 2608

Answers (1)

Luke Marlin
Luke Marlin

Reputation: 1398

First, and since you're using Prism, I suggest that you go with ModuleExport, as follows :

[ModuleExport("SnakeModule", typeof(IGame))]

But your problems actually comes from the fact you didn't set your class as a public one, therefore preventing the discovery of your module. So you need to change your code to this :

[ModuleExport("SnakeModule", typeof(IGame))]
public class SnakeModule : IGame
{
    public void Initialize()
    {
        Console.WriteLine("test");
    }

    public void StartGame()
    {
        throw new NotImplementedException();
    }

}

And it should be fine !

Upvotes: 4

Related Questions