Andremoniy
Andremoniy

Reputation: 34900

Running some actions before bind() method

I wonder, is any convenient and appropriate way to describe in Tapestry5 in AppModule some actions, which should be invoked before bind() method will run?

Of course, it is possible, to include such actions inside bind() method in top of method block. But it seems, that must be some other possibility for this.

BTW, @Startup is not eligible way for this, due in my case it uses already started services, but I need to some actions before services will be bound.

Upvotes: 0

Views: 63

Answers (3)

Howard M. Lewis Ship
Howard M. Lewis Ship

Reputation: 2337

Outside of Tawus' answer; no, there's nothing you can do, short of a static code block (which is standard Java, not Tapestry related).

Upvotes: 1

t6nn
t6nn

Reputation: 91

Sometimes I have found myself using an unnamed static block in the module class - mostly to initialize legacy services that my Tapestry services depend on. Something like:

public final class MyModule {

    static {
        // early set-up here
    }

    public static void bind(ServiceBinder binder) {
        // binding here
    }
}

This seems to improve the module code readability a bit, but at the same time could be somewhat difficult to set up for unit testing.

Upvotes: 1

Tawus
Tawus

Reputation: 504

If it is a Tapestry web application, you can extend TapestryFilter and have the initialization step there. Look into the source code of TapestryFilter for inspiration. Also see TapestryAppInitializer

Upvotes: 0

Related Questions