Skip to content

Commit

Permalink
Allow inject StorageService by name optionally #6
Browse files Browse the repository at this point in the history
  • Loading branch information
greenlaw110 committed Feb 17, 2020
1 parent 10d2170 commit 828e199
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# act-storage CHANGE LOG

0.16.0
* Allow inject StorageService by name optionally #6
* update to act-1.8.32
* update osgl-storage to 1.10.1

0.15.0 - 03/Nov/2019
* update to act-1.8.29

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<parent>
<groupId>org.actframework</groupId>
<artifactId>parent</artifactId>
<version>1.8.29</version>
<version>1.8.32-SNAPSHOT</version>
</parent>

<properties>
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/act/storage/StorageServiceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* #L%
*/

import act.Act;
import act.Destroyable;
import act.app.App;
import act.app.AppService;
Expand All @@ -31,6 +32,7 @@
import act.storage.db.util.Setter;
import org.osgl.$;
import org.osgl.exception.ConfigurationException;
import org.osgl.inject.NamedProvider;
import org.osgl.logging.LogManager;
import org.osgl.logging.Logger;
import org.osgl.storage.ISObject;
Expand All @@ -44,6 +46,7 @@
import java.util.Map;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Provider;
import javax.inject.Singleton;

/**
Expand Down Expand Up @@ -104,11 +107,29 @@ public class StorageServiceManager extends AppServicePlugin implements AppServic

private boolean isDestroyed;

private final Provider<IStorageService> SS_PROVIDER = new Provider<IStorageService>() {
@Override
public IStorageService get() {
return storageService(DEFAULT);
}
};

private final NamedProvider<IStorageService> SS_NAMED_PROVIDER = new NamedProvider<IStorageService>() {
@Override
public IStorageService get(String name) {
IStorageService ss = storageService(name);
if (null == ss && ("ss".equalsIgnoreCase(name) || "storageService".equalsIgnoreCase(name) || "svc".equalsIgnoreCase(name) || "service".equalsIgnoreCase(name))) {
return storageService(DEFAULT);
}
return ss;
}
};

public StorageServiceManager() {
}

@Override
protected void applyTo(App app) {
protected void applyTo(final App app) {
this.reset();
this.app = app;
initServices(app.config());
Expand All @@ -124,6 +145,13 @@ public StorageServiceManager resolve(App app) {
});
}
});
app.jobManager().on(SysEventId.PRE_START, new Runnable() {
@Override
public void run() {
app.injector().registerProvider(IStorageService.class, SS_PROVIDER);
app.injector().registerNamedProvider(IStorageService.class, SS_NAMED_PROVIDER);
}
});
app.eventBus().emit(new StorageServiceManagerInitialized(this));
}

Expand Down

0 comments on commit 828e199

Please sign in to comment.