MentaContainer

Compare Revisions

Ignore whitespace Rev 144 → Rev 145

/trunk/src/test/java/org/mentacontainer/impl/WrapperFactoryTest.java
13,7 → 13,7
String s = new String("saoj");
Factory<String> ic = new WrapperFactory<String>(s);
Factory<String> ic = new SingletonFactory<String>(s);
Container c = new MentaContainer();
/trunk/src/main/java/org/mentacontainer/impl/WrapperFactory.java
File deleted
\ No newline at end of file
/trunk/src/main/java/org/mentacontainer/impl/MentaContainer.java
43,7 → 43,7
String k = InjectionUtils.getKeyName(key);
Factory<?> factory = poolsByName.get(k);
Pool<?> factory = poolsByName.get(k);
if (factory == null) return null;
183,7 → 183,7
 
if (!poolsByName.containsKey(keyString)) return null;
 
Factory<?> c = poolsByName.get(keyString);
Pool<?> c = poolsByName.get(keyString);
Scope scope = scopes.get(keyString);
353,12 → 353,13
}
@Override
public <T> Factory<T> ioc(Object key, Factory<T> factory, Scope scope) {
return ioc(key, fromFactory(factory), scope);
public void ioc(Object key, Factory<?> factory, Scope scope) {
ioc(key, fromFactory(factory), scope);
}
@Override
public <T> Pool<T> ioc(Object key, Pool<T> factory, Scope scope) {
public void ioc(Object key, Pool<?> factory, Scope scope) {
String keyString = InjectionUtils.getKeyName(key);
374,20 → 375,18
scopes.put(keyString, scope);
forConstructMethod.add(new ConstructorDependency(keyString, factory.getType()));
return factory;
}
@Override
public <T> Factory<T> ioc(Object key, Factory<T> factory) {
public void ioc(Object key, Factory<?> factory) {
return ioc(key, fromFactory(factory));
ioc(key, fromFactory(factory));
}
@Override
public <T> Pool<T> ioc(Object key, Pool<T> pool) {
public void ioc(Object key, Pool<?> pool) {
return ioc(key, pool, Scope.NONE);
ioc(key, pool, Scope.NONE);
}
@Override
/trunk/src/main/java/org/mentacontainer/impl/SingletonFactory.java
New file
0,0 → 1,29
package org.mentacontainer.impl;
 
import org.mentacontainer.Factory;
 
public class SingletonFactory<E> implements Factory<E> {
private final E instance;
private final Class<E> type;
public SingletonFactory(E instance) {
 
this.instance = instance;
this.type = (Class<E>) instance.getClass();
}
@Override
public E getInstance() {
return instance;
}
@Override
public Class<E> getType() {
return type;
}
}
/trunk/src/main/java/org/mentacontainer/Container.java
71,7 → 71,7
* @return The factory passed as a parameter. (Fluent API)
* @see Factory
*/
public <T> Factory<T> ioc(Object key, Factory<T> factory);
public void ioc(Object key, Factory<?> factory);
/**
* Set up a pool for the given key. The scope assumed is NONE.
81,7 → 81,7
* @return The factory passed as a parameter. (Fluent API)
* @see Pool
*/
public <T> Pool<T> ioc(Object key, Pool<T> pool);
public void ioc(Object key, Pool<?> pool);
/**
* Set up a factory for the given key in the given scope.
93,7 → 93,7
* @see Factory
* @see Scope
*/
public <T> Factory<T> ioc(Object key, Factory<T> factory, Scope scope);
public void ioc(Object key, Factory<?> factory, Scope scope);
/**
* Set up a pool for the given key in the given scope.
105,7 → 105,7
* @see Pool
* @see Scope
*/
public <T> Pool<T> ioc(Object key, Pool<T> pool, Scope scope);
public void ioc(Object key, Pool<?> pool, Scope scope);
/**
* Configure a bean dependency to be auto-wired by the container.
/trunk/src/main/java/org/mentacontainer/Pool.java
1,7 → 1,10
package org.mentacontainer;
 
public interface Pool<E> extends Factory<E> {
public interface Pool<E> {
public E getInstance();
public Class<E> getType();
public void releaseInstance(E e);
}