Skip to content

Dependency Injection without dependency with Injector

License

Notifications You must be signed in to change notification settings

naskarlab/injector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Injector

Dependency Injection without dependency with Injector.

Features

  • Configuration over code: independence business code of the infrastructure code;
  • Intrusive-less: zero or less changes for your code;
  • Glue code: it’s only a small and simple classes set;
  • Fluent Builder: code complete is your friend!

Documentation: naskar lab

Using

<dependencies>
	<dependency>
		<groupId>com.naskar</groupId>
		<artifactId>injector</artifactId>
		<version>1.0.0</version>
	</dependency>
</dependencies>
<repositories>
	<repository>
		<snapshots>
			<enabled>false</enabled>
		</snapshots>
		<id>central</id>
		<name>libs-release</name>
		<url>http://repo.naskar.com.br/dist/libs-release</url>
	</repository>
</repositories>

Examples


@Before
public void setup() {
	this.ctx = new ApplicationContext()
		.include(x -> x.getName().startsWith("com.naskar.injector.test"))
		.register(If.implementsInterface(), Then.usingSingleton(), With.allInterfaces())
		.register(x -> x.getName().endsWith("Controller"), Then.usingPrototype(), With.asClass())
		.inject(By.property(If.allFields()))
		.create()
	;
}

@Test
public void testControllerInjectService() {
	Controller target = ctx.resolve(Controller.class);
	
	Assert.assertTrue(target.getService() != null);
}

@Test
public void testServiceInjectRepository() {
	Service target = ctx.resolve(Service.class);
	
	Assert.assertTrue(target.getRepository() != null);
}

@Test
public void testServiceInstance() {
	Service target = ctx.resolve(Service.class);
	
	Assert.assertTrue(target instanceof ServiceImpl);
}

@Test
public void testRepositoryInstance() {
	Repository target = ctx.resolve(Repository.class);
	
	Assert.assertTrue(target instanceof RepositoryImpl);
}
 

About

Dependency Injection without dependency with Injector

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages