1
votes

i have a solution with the following Structure:

project.Model

project.Builder

project.Unit Tests

in the builder project it should create a Model instance using MEF. so in the Builder class constructor i want it to have a container to hold the parts related to building the model only(as a separation of concerns) .

currently i am using the directory catalog as follows:

var path = Environment.CurrentDirectory;
var catalog = new DirectoryCatalog(path + @"\Builder\bin\Debug");

so that in the unit test project i can use this container in writing the unit tests functions. is there a better way to make the builder container have only the dlls that resides in the builder project output directory (bin\debug). I have tried using:

var directory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var catalog = new DirectoryCatalog(directory);

bu this have make the catalog to scan the output directory of the unit tests projects which have made a lot of problems other than being not where I want the catalog to scan.

is there a more correct way than what I'm currently doing ? thanks in advance.

1

1 Answers

0
votes

I would rather use and AssemblyCatalog - and add a static reference from Builder project to Model project, so you can avoid all problems with folders - scanning the whole folder, directory structure change during deployment, different versions of assembly in the same folder, etc. The code would look something like

var catalog = new AssemblyCatalog(typeof(YourModelType).Assembly);