-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
770f2a2
commit 2695787
Showing
11 changed files
with
61 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/ch/mare/springfundamentals/beanscopes/PrototypeComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ch.mare.springfundamentals.beanscopes; | ||
|
||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Scope("prototype") | ||
public class PrototypeComponent { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/ch/mare/springfundamentals/beanscopes/SingletonComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ch.mare.springfundamentals.beanscopes; | ||
|
||
import org.springframework.context.annotation.Scope; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Scope("singleton") | ||
public class SingletonComponent { | ||
|
||
} |
5 changes: 4 additions & 1 deletion
5
src/main/java/ch/mare/springfundamentals/dependencyinjection/di_01/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package ch.mare.springfundamentals.dependencyinjection.di_01; | ||
|
||
import ch.mare.springfundamentals.dependencyinjection.di_01.controller.CustomerController; | ||
|
||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
|
||
CustomerController customerController = new CustomerController(); | ||
customerController.deactivateCustomerAccount("1"); | ||
} | ||
|
||
} |
7 changes: 6 additions & 1 deletion
7
...a/ch/mare/springfundamentals/dependencyinjection/di_01/controller/CustomerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package ch.mare.springfundamentals.dependencyinjection.di_01.controller; | ||
|
||
public class CustomerController { | ||
import ch.mare.springfundamentals.dependencyinjection.di_01.service.CustomerService; | ||
|
||
public class CustomerController { | ||
|
||
public void deactivateCustomerAccount(String customerId) { | ||
CustomerService customerService = new CustomerService(); | ||
customerService.deactivateCustomer(customerId); | ||
} | ||
|
||
} |
12 changes: 1 addition & 11 deletions
12
.../java/ch/mare/springfundamentals/dependencyinjection/di_01/dataaccess/CustomerLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,10 @@ | ||
package ch.mare.springfundamentals.dependencyinjection.di_01.dataaccess; | ||
|
||
import ch.mare.springfundamentals.dependencyinjection.common.domain.Customer; | ||
import ch.mare.springfundamentals.dependencyinjection.common.domain.MailingAddress; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class CustomerLoader { | ||
|
||
|
||
private static final Map<String, Customer> DATABASE = new HashMap<>() {{ | ||
put("1", new Customer("1", "Hans Wurst", new MailingAddress("Hauptstrasse 2", "Zürich"), "[email protected]")); | ||
put("2", new Customer("2", "Peter Peterson", new MailingAddress("Bahnhofsweg 100", "Bern"), "[email protected]")); | ||
}}; | ||
|
||
public Customer findById(String customerId) { | ||
return DATABASE.get(customerId); | ||
return InMemoryDatabase.DATABASE.get(customerId); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ava/ch/mare/springfundamentals/dependencyinjection/di_01/dataaccess/InMemoryDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ch.mare.springfundamentals.dependencyinjection.di_01.dataaccess; | ||
|
||
import ch.mare.springfundamentals.dependencyinjection.common.domain.Customer; | ||
import ch.mare.springfundamentals.dependencyinjection.common.domain.MailingAddress; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class InMemoryDatabase { | ||
|
||
public static final Map<String, Customer> DATABASE = new HashMap<>() {{ | ||
put("1", new Customer("1", "Hans Wurst", new MailingAddress("Hauptstrasse 2", "Zürich"), "[email protected]")); | ||
put("2", new Customer("2", "Peter Peterson", new MailingAddress("Bahnhofsweg 100", "Bern"), "[email protected]")); | ||
}}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Profile({"mock"}) | ||
public class CustomerLoaderMock implements CustomerLoader { | ||
private static final Map<String, Customer> DATABASE = new HashMap<>() {{ | ||
put("1", new Customer("1", "Hans Tester", new MailingAddress("Teststrasse 2", "Zürich"), "[email protected]")); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters