Skip to content

Commit

Permalink
Rework GmodelState binding
Browse files Browse the repository at this point in the history
Bind actual implementation class of GModelState to itself as singleton before binding it to GModelState.
e.g. by overriding the following method of `GLSPDiagramModule`

```java
bindGModelState(){
  return MyModelState.class
}
```

clients can also directly inject the implementing subclass with
```java
@Inject 
protected MyModelState myModelState;
```

Also fix type in `GLSPServerModule`
  • Loading branch information
tortmayr committed Oct 25, 2021
1 parent 260269a commit 1d33c76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected void configureBase() {
bind(DiagramConfiguration.class).to(bindDiagramConfiguration()).in(DiagramGlobalSingleton.class);
bind(ServerConfigurationContribution.class).to(bindServerConfigurationContribution()).in(Singleton.class);
// Model-related bindings
bind(GModelState.class).to(bindGModelState()).in(Singleton.class);
configureGModelState(bindGModelState());
bind(ModelSourceLoader.class).to(bindSourceModelLoader());
bind(GModelFactory.class).to(bindGModelFactory());
bindOptionally(ModelSourceWatcher.class, bindModelSourceWatcher())
Expand Down Expand Up @@ -225,6 +225,11 @@ protected Class<? extends ServerConfigurationContribution> bindServerConfigurati
return DefaultServerConfigurationContribution.class;
}

protected void configureGModelState(final Class<? extends GModelState> gmodelStateClass) {
bind(gmodelStateClass).in(Singleton.class);
bind(GModelState.class).to(gmodelStateClass);
}

protected Class<? extends GModelState> bindGModelState() {
return DefaultGModelState.class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class ServerModule extends GLSPModule {
public ServerModule configureDiagramModule(final DiagramModule diagramModule, final Module... mixinModules) {
String diagramType = diagramModule.getDiagramType();
Preconditions.checkState(!diagramModules.containsKey(diagramType),
"A module configuration is alreay present for diagram type: " + diagramType);
"A module configuration is already present for diagram type: " + diagramType);

Module combinedModule = ModuleUtil.mixin(diagramModule, mixinModules);
diagramModules.put(diagramType, combinedModule);
Expand Down

0 comments on commit 1d33c76

Please sign in to comment.