Skip to content

Commit

Permalink
Instantiate UI Instance with Instantiator class (#7446)
Browse files Browse the repository at this point in the history
Update MockInstantiator
  • Loading branch information
jhult committed Feb 22, 2020
1 parent bfcade6 commit 648925a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Expand Up @@ -21,6 +21,7 @@
import java.util.stream.StreamSupport;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.i18n.I18NProvider;
import com.vaadin.flow.internal.ReflectTools;
Expand Down Expand Up @@ -71,6 +72,11 @@ public <T extends Component> T createComponent(Class<T> componentClass) {
return create(componentClass);
}

@Override
public <T extends UI> T createUI(Class<T> uiClass) {
return create(uiClass);
}

/**
* Helper for finding service init listeners using {@link ServiceLoader}.
*
Expand Down
12 changes: 12 additions & 0 deletions flow-server/src/main/java/com/vaadin/flow/di/Instantiator.java
Expand Up @@ -202,6 +202,18 @@ default <T extends HasElement> T createRouteTarget(Class<T> routeTargetType,
*/
<T extends Component> T createComponent(Class<T> componentClass);

/**
* Creates an instance of a UI by its {@code uiClass}.
*
* @param uiClass
* the instance type to create, not <code>null</code>
* @param <T>
* the UI type
*
* @return the created instance, not <code>null</code>
*/
<T extends UI> T createUI(Class<T> uiClass);

/**
* Gets the instantiator to use for the given UI.
*
Expand Down
Expand Up @@ -59,7 +59,6 @@
import com.vaadin.flow.component.page.Viewport;
import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.internal.AnnotationReader;
import com.vaadin.flow.internal.ReflectTools;
import com.vaadin.flow.internal.UsageStatisticsExporter;
import com.vaadin.flow.server.communication.AtmospherePushConnection;
import com.vaadin.flow.server.communication.PushConnectionFactory;
Expand Down Expand Up @@ -1148,7 +1147,7 @@ protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass,
VaadinRequest request, VaadinResponse response,
VaadinSession session) {

UI ui = ReflectTools.createInstance(uiClass);
UI ui = request.getService().getInstantiator().createUI(uiClass);
ui.getInternals().setContextRoot(
request.getService().getContextRootRelativePath(request));

Expand Down
Expand Up @@ -18,6 +18,7 @@
import java.util.stream.Stream;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.di.Instantiator;
import com.vaadin.flow.internal.ReflectTools;

Expand All @@ -41,11 +42,20 @@ public Stream<VaadinServiceInitListener> getServiceInitListeners() {

@Override
public <T> T getOrCreate(Class<T> type) {
return ReflectTools.createInstance(type);
return create(type);
}

@Override
public <T extends Component> T createComponent(Class<T> componentClass) {
return ReflectTools.createInstance(componentClass);
return create(componentClass);
}

@Override
public <T extends UI> T createUI(Class<T> uiClass) {
return create(uiClass);
}

private <T> T create(Class<T> type) {
return ReflectTools.createInstance(type);
}
}

0 comments on commit 648925a

Please sign in to comment.