Consider simple Calendar application, which locates on http://localhost/cal#!month
So I have one View for rendering calendar’s month. Also one EventService is autowired to this class.
[code]
@SpringView(“month”)
public class MonthView extends VerticalLayout implements View {
@Autowired
private EventService eventService;
…
[/code]No when user for example clicks on some Event, we can load some event details from eventService and render EventDetailModal. Let it be something like this.
[code]
public class EventDetailModal extends Window {
public EventDetailModal(Event event) {
…
[/code]So in this Window I can render out some event details more precisely. But also in this view, I have some event commenting options, so user could add comments to events. For this I have EventCommentService and this need to be it accessed from EventDetailModal.
I don’t want to do something like this, were I pass Domain object and Service class through constructor.
[code]
public class EventDetailModal extends Window {
public EventDetailModal(Event event, EventCommentService eventCommentService) {
…
[/code]Also when I have multiple nested components inside each other, it would get quickly messy to pass all services from initial View class to sub UI component, which requires this service.
I would like to achieve something like this:
public class EventDetailModal extends Window {
@Autowired
EventCommentService eventCommentService;
public EventDetailModal(Event event) {
...
Also I think in complex application, it would get messy when I would do this through some callbacks etc.
One idea I had, was that I could do something like this through Builder helper class, eg:
@Component
public class EventDetailModalBuilder {
@Autowired
private EventCommentService eventCommentService;
EventDetailModal build(Event event) {
...
}
class EventDetailModal extends Window {
public EventDetailModal(Event event) {
...
Or have anybody some ideas how to solve such kind of problem?