问题
Would it be better, for example, to pass context.getExternalContext().getRequestLocale()
to the EJB by parameter, instead of using an import and getCurrentInstance from inside the EJB?
import javax.faces.context.FacesContext;
FacesContext.getCurrentInstance()
(I'm new to web development)
回答1:
If you think of your software system as a three layer architecture then the FacesContext
(which is part of the JSF framework) belongs to the presentation layer and the EJB
to the application layer.
In general it's bad software design when a lower layer (application) depending on higher layer (Presentation). It leads to high coupling, low cohesion and therefore overall to poor software quality.
To sum it up, it would be better to pass the values by parameter instead of accessing the FacesContext
from a EJB
.
来源:https://stackoverflow.com/questions/37554150/is-it-a-bad-design-for-a-ejb-to-depend-on-facescontext