Export to GitHub

linfu - issue #7

File naming


Posted on Dec 18, 2008 by Massive Panda

Hi Philipp, I have an issue regarding file names.

By default, I'm used to have interface and implementation in separated dlls, named "xyz.dll" and "xyz.implementation.dll". For example:

interface ICalculator in Calculator.dll class Calculator (which implements ICalculator) in Calculator.Implementation.dll

Now the following does not work: serviceContainer = new ServiceContainer(); serviceContainer.LoadFrom(IMPLEMENTATIONDIRECTORY, "*.dll"); instanceUnderTest = serviceContainer.GetService<ICalculator>();

But when I use this instead it does: serviceContainer.LoadFrom(IMPLEMENTATIONDIRECTORY, "*.Implementation.dll");

Obviously, the naming scheme 'abc.xyz.dll' is not properly recognized. This should not be hard to resolve...

Apart from that, congrats and thanks for your great work. I'm using LinFu.IoC 2.0 on a regular basis and am very happy with it.

Regards Thomas

Comment #1

Posted on Dec 29, 2008 by Massive Bird

Hi Thomas,

Unfortunately, there's not much I can do here since this is the default behavior for the System.IO.Directory.GetFiles() method. The wildcard pattern that you pass to the ServiceContainer.LoadFrom() method will ultimately be handled by the Directory.GetFiles() method, and for obvious reasons, I don't think I'll be able to modify the implementation for that class. However, if it really becomes an issue, you can always provide your own implementation of IDirectoryListing and 'manually' use the Loader class to configure the container, like this:

internal class RegExDirectoryLister : IDirectoryListing
{
    public IEnumerable<string> GetFiles(string path, string searchPattern)
    {
        // Return the list of files that match the regex searchPattern here
        // ...
    }
}

...and in the client code:

var yourContainer = new ServiceContainer(); var loader = new Loader(); loader.DirectoryLister = new RegExDirectoryLister(); loader.LoadFrom(AppDomain.CurrentDomain.BaseDirectory, "YourRegexPatternHere");

// Configure the target container loader.LoadInto(yourContainer);

I know it's it's not pretty, but it's the simplest possible thing that can work. If this becomes a major issue, I'll put this up on the TODO list for the next release.

Comment #2

Posted on Dec 29, 2008 by Massive Bird

(No comment was entered for this change.)

Comment #3

Posted on Jan 21, 2009 by Grumpy Rabbit

Maybe get the full file list and enumerate over the list with a regular expression?

Status: Accepted

Labels:
Type-Defect Priority-Medium