Skip to content

Latest commit

 

History

History
47 lines (30 loc) · 2.45 KB

README.md

File metadata and controls

47 lines (30 loc) · 2.45 KB

Hura Web

Hura's Web setup combines the injection functionality of the core with the Java Servlet 4 specification.

1. Running Hura injected web applications

1.1 Launching the application

To launch a web application injected by Hura, implement the interface HuraWebApplicationInitializer, which...

  • is marked as a ServletContainerInitializer, so it will be picked up by servlet container providers
  • extends Hura's Blueprint to allow defining the web environment of the application using dependency injection
public class SomeWebApplication implements HuraWebApplicationInitializer {
    // define stuff here
}

1.2 Running the application

The HuraWebApplicationInitializer implementation is injected by a RootInjector by Hura Web, allowing the beans defined by the Blueprint to retrieve an Injector instance injected by the applications root injection sequence.

From there, the beans can build up and tear down the application arbitrarily in as many sub sequences as desired when requests are retrieved by components of the application's entities.

1.3 Shutting the application down

As mentioned before, the HuraWebApplicationInitializer is being injected by a RootInjector on application startup.

When the servlet container provider shuts down, that RootInjector is shut down by Hura Web. As a result, the initializer and all beans originating from it will be destroyed automatically when the application shuts down, effectively cleanly ending their natural bean life cycle.

2. Defining the Web Environment

The environment of a web application consists of servlet specification entities registered as the container provider, with the main entity being the Servlet.

Hura web allows such entities to be defined by creating singleton beans implementing ServletContextConfiguration. The interface can be implemented freely, but the WebEnvironmentFactory provides implementations for standard use cases.

SingletonAllocation instances defined by a HuraWebApplicationInitializer implementation holding a bean implementing ServletContextConfiguration will be automatically registered with the servlet container provider:

public class SomeWebApplication implements HuraWebApplicationInitializer {
    
    @Define
    public Blueprint.SingletonAllocation defineServlet() {
        return WebEnvironmentFactory.registerServlet(SomeServlet.class).build();
    }
}