Replies: 5 comments 17 replies
-
Would it not be more clean and correct to just add the type to the Closure parameter? class BootStrap {
def init = { ServletContext servletContext ->
}
def destroy = {
}
} |
Beta Was this translation helpful? Give feedback.
-
Well, this broke my app.... I use it servletContext.setAttribute('availableLocales', localeService.getAvailableLocales()) What was the benefit in removing it? couldn't |
Beta Was this translation helpful? Give feedback.
-
In my opinion, it is simple in design and seemingly generic but can be easily abused and difficult to maintain, so I don't recommend using BootStrap. But I'm curious to see what scenarios you use in your real-world projects? I'm willing to recommend some better alternatives. |
Beta Was this translation helpful? Give feedback.
-
I also think that using methods instead of Closures is the better way to go. And make sure that this change is backwards compatible, with only a few modifications to support both ways. class BootStrap {
ServletContext servletContext
def init() {
}
def destroy() {
}
}
public class DefaultGrailsBootstrapClass {
public void callInit(ServletContext servletContext) {
Closure<?> init = getInitClosure();
if (init != null) {
Class<?>[] parameterTypes = init.getParameterTypes();
if (parameterTypes != null) {
init = init.curry(new Object[] { servletContext });
}
Environment.executeForCurrentEnvironment(init);
}
else {
// Invoke the init() method
InvokerHelper.invokeMethod(this.instance, 'init', new Object[0]);
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Since we can inject
ServletContext
inBootStrap.groovy
I am proposing to cleanup theinit
closure from this:to this:
Benefits:
init
code changeServletContext
from other artifacts like Controllers, Services, etc..servletContext
Beta Was this translation helpful? Give feedback.
All reactions