Skip to content

yueliangwen/system-dependency-injection

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dependency injection example with system

Definition

This is an example for the system library. It shows how to leverage the dependency injection features of component, the libary on top of which system itself is built.

Mission statement

Names are important. Which names? Those behind our favorite movies, that’s who! So let’s save them via a web service.

Installation

In our development environment, we use a in-memory database and a web server listening on port 3025.

$ boot dev-run

In our production environment, we use a persistent database and a web server listening on port 8008.

$ boot prod-run

To connect with a REPL to the running system.

$ boot dev

Usage

To search for a movie’s director:

curl -H "Content-Type: application/edn" -X POST -d '{:movie "Realm of the Senses"}' http://localhost:3025/movie 
{:director ("Nagisa Ōshima")}

To add a director to our database:

curl -H "Content-Type: application/edn" -X PUT -d '{:director "Nagisa Ōshima"}' http://localhost:3025/director

To list directors in our database:

curl http://localhost:3025/directors
("Nagisa Ōshima")

Let’s look for another all-time favorite.

curl -H "Content-Type: application/edn" -X POST -d '{:movie "Professione: reporter"}' http://localhost:3025/movie 
{:director ("Michelangelo Antonioni")}

Now that we know the name of the director, we can persist it to our database.

curl -H "Content-Type: application/edn" -X PUT -d '{:director "Michelangelo Antonioni"}' http://localhost:3025/director

Let’s verify it’s there:

curl http://localhost:3025/directors
("Nagisa Ōshima" "Michelangelo Antonioni")

Let’s repeat this one more time for a third movie/director:

curl -H "Content-Type: application/edn" -X POST -d '{:movie " À bout de souffle"}' http://localhost:3025/movie 
{:director ("Jean-Luc Godard")}

Saving to database:

curl -H "Content-Type: application/edn" -X PUT -d '{:director "Jean-Luc Godard"}' http://localhost:3025/director

We should now have three directors in our database:

curl http://localhost:3025/directors
("Nagisa Ōshima" "Michelangelo Antonioni" "Jean-Luc Godard")

Let’s suppose we want to remove one.

curl -H "Content-Type: application/edn" -X DELETE -d '{:director "Nagisa Ōshima"}' http://localhost:3025/director

Let’s verify the removal was properly executed.

curl http://localhost:3025/directors
("Michelangelo Antonioni" "Jean-Luc Godard")

About

Example for dependency injection with system

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Clojure 100.0%