Skip to content

tahonaPL/di

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tahona DI

Automatic dependency injection that works on Desktop, Web and Android.

Spring support library: here

Installation

Maven:

<groupId>pl.tahona</groupId>
<artifactId>di</artifactId>
<version>1.0.0</version>

Gradle:

  compile 'pl.tahona:di:1.0.0'

Basic use:

Container initialization

//Create Injector:
	final Injector injector = new Injector();

//Register beans
	injector.register(AnnotationScopeLocalBean.class);
	injector.register(UserService.class);
	injector.register(ClientService.class);
	injector.register(ConnectionService.class);
		
	final BeanContainer beanContainer = new BeanContainer(injector);
	beanContainer.initialize();

Bean injection @Wire

class UserService {
  @Wire private ConnectionService connectionService;
  //...
}

Bean injection - constructor

@Service
class UserService {
    private ConnectionService connectionService;

    public UserService (ConnectionService connectionService) {
        this.connectionService = connectionService;
    }
}

@Init annotation

Method executed after bean injection.

 class UserService {
 	@Wire private ConnectionService connectionService;

  	@Init
  	private init () {
        connectionService.prepareForConnection();
  	}
}

Bean Scanner

@Component
class UserService {
    @Wire private ConnectionService connectionService;

    @Init
    private init () {
        connectionService.prepareForConnection();
    }
}

...

Map<String,Class> classes = new BeanScanner("com.test").scan();
Injector in = new Injector()
in.registerAll(classes);

BeanContainer b = new BeanContainer(in);
b.initialize()

Spring annotations (@Component, @Service, @Repository) are in DI-Spring

About

DI - dependency injection tool

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages