Skip to content

Commit 0da5796

Browse files
committed
Merge branch 'master' of https://gitee.com/techarts/whale
2 parents d905dd4 + 0c97670 commit 0da5796

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

README.md

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,17 @@ public class WhaleTest{
128128
//Or read configuration from a properties file
129129
//var context = Context.make("/tmp/project/demo/config.properties");
130130

131-
var factory = context.createFactory();
132-
factory.scan("/tmp/project/demo/bin");
131+
var loader = context.getLoader();
132+
loader.scan("/tmp/project/demo/bin");
133133

134134
//If you have more than one classpath:
135-
//factory.scan("Another classpath");
136-
//factory.scan("classpath-1", "class-path2");
135+
//loader.scan("Another classpath");
136+
//loader.scan("classpath-1", "class-path2");
137137

138-
factory.start();
138+
context.start();
139139

140140
//The chain-stype calling is supported:
141-
//context.createFactory().scan("/tmp/project/demo/bin").start();
141+
//context.getLoader().scan("/tmp/project/demo/bin").start();
142142

143143
var person = context.get(Person.class);
144144
var mobile = context.get(Mobile.class);
@@ -156,13 +156,13 @@ public class WhaleTest{
156156
@Test
157157
public void testRegisterManually(){
158158
var context = Context.make(CONFIGS);
159-
var factory = context.createFactory();
160-
factory.register(Person.class);
161-
factory.register(Mobile.class);
162-
factory.start();
159+
var binder = context.getBinder();
160+
binder.register(Person.class);
161+
binder.register(Mobile.class);
162+
context.start();
163163

164164
//Chain-style calling:
165-
//factory.register(Person.class, Mobile.class).start();
165+
//binder.register(Person.class, Mobile.class).start();
166166

167167
var person = context.get(Person.class);
168168
var mobile = context.get(Mobile.class);
@@ -178,11 +178,11 @@ We assume to packed these 2 classes into a JAR file "/tmp/project/demo/lib/demo.
178178
@Test
179179
public void testLoadFromJAR(){
180180
var context = Context.make(CONFIGS);
181-
var factory = context.createFactory();
182-
factory.load("/tmp/project/demo/lib/demo.jar");
183-
factory.start();
181+
var loader = context.getLoader();
182+
loader.load("/tmp/project/demo/lib/demo.jar");
183+
context.start();
184184
185-
var person = context.get(Person.class);
185+
var person = context.get(Person.class);
186186
var mobile = context.get(Mobile.class);
187187
TestCase.assertEquals(18, person.getAge());
188188
TestCase.assertEquals("John Denver", person.getName());
@@ -235,9 +235,9 @@ More advanced features are forbidden because it makes the XML schema very ugly.
235235
@Test
236236
public void testParseXMLDefinition(){
237237
var context = Context.make(CONFIGS);
238-
var factory = context.createFactory();
239-
factory.parse("/tmp/project/demo/beans.xml");
240-
factory.start();
238+
var loader = context.getLoader();
239+
loader.parse("/tmp/project/demo/beans.xml");
240+
context.start();
241241

242242
//Chain-stype calling
243243
//context.createFactory().parse("/tmp/project/demo/beans.xml").start();
@@ -253,7 +253,7 @@ More advanced features are forbidden because it makes the XML schema very ugly.
253253
```
254254
You can actually pass multiple XML definitions to the method parse. For example:
255255
```java
256-
factory.parse("/tmp/project/demo/beans-1.xml", "/tmp/project/demo/beans-2.xml");
256+
loader.parse("/tmp/project/demo/beans-1.xml", "/tmp/project/demo/beans-2.xml");
257257
```
258258

259259
## 4. Provider<T>
@@ -381,7 +381,7 @@ public class Demo{
381381
Certainly, you can call the bind method manually in code:
382382

383383
```java
384-
factory.bind(DemoService.class, DemoServiceImpl.class);
384+
binder.bind(DemoService.class, DemoServiceImpl.class);
385385
```
386386

387387
To summarize, the Bind annotation provides a straightforward way for mapping an abstraction (interface or abstract class) to its concrete implementation, simplifying the dependence configuration.
@@ -394,12 +394,12 @@ Whale offers the flexibility to append managed objects into DI container even af
394394
@Test
395395
public void testAppendBeans(){
396396
var context = Context.make(CONFIGS);
397-
var factory = context.createFactory();
398-
factory.register(Person.class);
399-
factory.register(Mobile.class);
400-
factory.start(); //Container Initialized
397+
var binder = context.getBinder();
398+
binder.register(Person.class);
399+
binder.register(Mobile.class);
400+
context.start(); //Container Initialized
401401

402-
factory.append(DemoServiceImpl.class);
402+
binder.append(DemoServiceImpl.class);
403403

404404
var person = context.get(Person.class);
405405
var mobile = context.get(Mobile.class);
@@ -482,6 +482,20 @@ public void init(){
482482
```
483483
Whale does not provide the finalizer annotation. You should implement the AutoCloseable interface. When the DI container is shutdown, the close method will be called automatically.
484484

485+
### E. Import external singleton object(Non-JSR330) as a managed bean into container:
486+
487+
```java
488+
public void testIncludeObject(){
489+
var context = Context.make();
490+
var binder = context.getBinder();
491+
binder.include(new Object());
492+
binder.include(new Object(), "myObject");
493+
context.start();
494+
TestCase.assertEequals(true, context.get("myObject") != null);
495+
TestCase.assertEquaqls(true, context.get(Object.class) != null);
496+
TestCase.assertEquals(false, context.get("myObject") == context.get(Object.class));
497+
}
498+
```
485499

486500
## 6. Web Application
487501

@@ -506,5 +520,6 @@ public DemoServlet extends HttpServlet{
506520
## 7. Todo List
507521
We plan to add the following features:
508522
- Interceptor and Enhancer annotations.
523+
- Support namespace or module
509524
- Refactor code to improve performance.
510525
- Fix bugs as soon as they are found.

0 commit comments

Comments
 (0)