Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdi-dev] This is StillDI

On Tue, Mar 9, 2021 at 1:06 PM Andrew Rouse <ANROUSE@xxxxxxxxxx> wrote:
From: Ladislav Thon <lthon@xxxxxxxxxx>

1. Is there a portable way to run some code during application startup? The `@Initialized(ApplicationScoped.class) Object` event is fired during container initialization, which can be during application build, so that's not it. I propose CDI standardizes an `AfterStartup` event (symmetrically to existing `BeforeShutdown`), which is guaranteed to be fired during application startup. I personally find `AfterStartup` and `BeforeShutdown` a lot more natural than `@Initialized(ApplicationScoped.class) Object` and `@Destroyed(ApplicationScoped.class) Object`.  (Though to be perfectly honest, `BeforeShutdown` seems misnamed and, since all CDI contexts are invalid at that point in time, also quite useless.)
 
This is easy to implement in a fully runtime environment, so I took the liberty of adding that to StillDI, even though it isn't part of the extension API.
Is there some reason that the `@Initialized(ApplicationScoped.class) Object` event has to run at build time? Could it just be specified that it happens at runtime?
 
Currently I think this is the only way to ensure that something runs at startup with CDI so it would be a shame to break things that rely on that.

Matej said it better than I can, but I'll reply anyway :-)

The issue is that the `@Initialized(ApplicationScoped.class) Object` event isn't fired during application startup. It's fired when the application context is initialized. So far, this has always been the same, but fundamentally, it's not.

We seek to enable significant optimizations by potentially moving a lot of CDI startup to build time (including the whole bean discovery, extension processing, and more). This includes initialization of the application context.

LT
 
 
Regards,
Andrew
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU

_______________________________________________
cdi-dev mailing list
cdi-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdi-dev

Back to the top