Skip to content

AlaaMezian/Strategy-Technique-Spring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Framework Provide Implementation Based on User Request

provide proper implementation based on user request

this repository containt an example on how to use strategy in a dynamic way ,where a user can provide some info in the request that will make the application choose/provide a service implementation in run time based on what the user want and provided in the request

this example demonstrate how we can make a good use of some hidden spring boot framework features and the power of spring boot framework ,

we have language service as the following :

public interface LanguageService {

      String greet();
}

for example a user want english language thus the english implementation will be the implementation of the language service interface for this request

public class EnglishLanguage implements LanguageService {

	@Override
	public String greet() {
		return "Hello World!";
	}

}

and for another language such as arabic the following implementation

public class ArabicLanguage implements LanguageService{

	@Override
	public String greet() {
		return "اهلا بالعالم!";
	}

}

so each time i provide in the header a different param , the application will inject the proper implementation based on that param .

Please go inside the repository to get the bigger picture 👉

Tweet ✌️

About

Spring Boot dependency injection based on user request

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages