Mediator without a view?

Gerry Koh's Avatar

Gerry Koh

27 Aug, 2010 06:05 PM

Hi,

I am trying to create a mediator without a view to to separate out metrics business logic from the component being monitored. This mediator listens for events and then fires off metrics calls, making it the information expert for metrics in the application.

How do I register this mediator? Is this the right approach?

Thanks,

gerry

  1. 1 Posted by Jason Dias on 27 Aug, 2010 06:13 PM

    Jason Dias's Avatar

    Sounds more like a Controller or Model, and you can use any of the following
    `mapSingleton`
    `mapSingletonOf`
    `mapClass`
    `injectInto`

    Jason

  2. 2 Posted by Gerry Koh on 27 Aug, 2010 06:34 PM

    Gerry Koh's Avatar

    I'm not sure I understand your suggestion. Are you saying that i should have a separate controller or model for metrics? My goal is to have the application that i'm monitoring have as little metrics knowledge as possible, including what events are being monitored.

    Right now I'm mapping events to a MetricsCommand and calling the metrics service there, but knowledge of which events are being tracked is hard coded into the Context.

    My hope is that with a 'floating' Mediator, that knowledge will also be contained within the same file that holds the business logic.

  3. 3 Posted by Jason Dias on 27 Aug, 2010 07:07 PM

    Jason Dias's Avatar

    Well, I was answering the general question of mapping something without a view.

    With what you have described it sounds like you are doing things fine you just need to extract the "metric" mappings from the context and put them into their own command, something like ConfigureMetricCommands, and then do all your mappings in there.

    If you want everything contained in the same file, you can create that class and inject the service and the eventDispatcher, then listen for the events you want and then call the service.

  4. 4 Posted by Gerry Koh on 27 Aug, 2010 07:22 PM

    Gerry Koh's Avatar

    That makes sense, thanks.

    However I was under the impression that for injection to work i would somehow have to let the framework know that the class exists?

    If I create MetricsManager.as and put Inject tags into it, do I need to do anything else for the injections to work?

    thanks,

    g

  5. 5 Posted by Jason Dias on 27 Aug, 2010 07:28 PM

    Jason Dias's Avatar

    Yes that is correct.

    Any of these would do that for you
    mapSingleton mapSingletonOf mapClass injectInto

    Which one you use depends on how you want to use the MetricManager throughout your application, I would probably use mapSingleton for this.

    So in your context you would do injector.mapSingleton(MetricManager);

  6. 6 Posted by Gerry Koh on 27 Aug, 2010 07:31 PM

    Gerry Koh's Avatar

    thanks!

  7. Gerry Koh closed this discussion on 22 Oct, 2010 10:27 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac