views:

39

answers:

1

I have two projects 1: windows forms project and 2: a business logic project that recursively walks the file system looking for specific files.

I want the windows project to subscribe to an event buried in a class called recurse. The problem I have is the instance of the recurse class is instantiated inside a facade class in the business logic project.

The windows forms project calls the business logic via a facade like so:

        FileAnalyzerFacade fileAnalyzerFacade = new FileAnalyzerFacade();
        fileAnalyzerFacade.WalkDirectory(path, searchFilter));

In project 2 the FileAnalyzerFacade() creates an instance of the Recurse() class. The Recurse() class raises an event when it finds a file. So the windows form knows nothing about the Recurse() class only the outer facade FileAnalyzerFacade().

The facade has the following subscription:

recurse.FileFound += new FilePropertyEventHandler(analyzeFile);

When the event is fired the analyzeFile() is run.

This is all fine as the FileAnalyzerFacade() creates the instance of the recurse class. How can I get the windows project to subscribe to the event raised inside the recurse class?

+1  A: 

Actually, you are trying to break Law of Demeter here. Therefore I suggest you to review your design. But the simplest option would be to expose similar event in your Facade class, or provide an additional delegate parameter to the WalkDirectory method.

Vitaliy Liptchinsky