-
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
6b94e26
commit 185e026
Showing
11 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/main/java/ch/mare/springfundamentals/beanscopes/AppConfig.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,8 @@ | ||
package ch.mare.springfundamentals.beanscopes; | ||
|
||
import org.springframework.context.annotation.ComponentScan; | ||
|
||
@ComponentScan(basePackages = {"ch.mare.springfundamentals.beanscopes._01"}) | ||
public class AppConfig { | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/ch/mare/springfundamentals/beanscopes/Main.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,16 @@ | ||
package ch.mare.springfundamentals.beanscopes; | ||
|
||
import ch.mare.springfundamentals.dependencyinjection.di_03.CustomerController; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class); | ||
|
||
CustomerController customerController = ctx.getBean(CustomerController.class); | ||
|
||
customerController.removeCustomerAccount("123"); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,16 +2,28 @@ | |
|
||
public class Customer { | ||
|
||
private String id; | ||
private String name; | ||
private MailingAddress mailingAddress; | ||
private String emailAddress; | ||
|
||
public Customer(String id, String name, MailingAddress mailingAddress, String emailAddress) { | ||
this.id = id; | ||
this.name = name; | ||
this.mailingAddress = mailingAddress; | ||
this.emailAddress = emailAddress; | ||
} | ||
|
||
public boolean hasEmailAddress() { | ||
return true; | ||
return emailAddress != null && !emailAddress.isEmpty(); | ||
} | ||
|
||
public String getEmailAddress() { | ||
return "[email protected]"; | ||
return emailAddress; | ||
} | ||
|
||
public MailingAddress getMailingAddress() { | ||
return new MailingAddress(); | ||
return mailingAddress; | ||
} | ||
|
||
public void deactivate() { | ||
|
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
9 changes: 9 additions & 0 deletions
9
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ch.mare.springfundamentals.dependencyinjection.di_01; | ||
|
||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
|
||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ch.mare.springfundamentals.dependencyinjection.di_01.controller; | ||
|
||
public class CustomerController { | ||
|
||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
.../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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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); | ||
} | ||
|
||
} |
8 changes: 6 additions & 2 deletions
8
...dencyinjection/di_01/CustomerService.java → ...ection/di_01/service/CustomerService.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
8 changes: 8 additions & 0 deletions
8
src/main/java/ch/mare/springfundamentals/dependencyinjection/di_01/service/EmailService.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,8 @@ | ||
package ch.mare.springfundamentals.dependencyinjection.di_01.service; | ||
|
||
public class EmailService { | ||
|
||
public void send(String emailAddress, String subject, String message) { | ||
System.out.println("Email with subject " + subject + " has been sent to " + emailAddress); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...main/java/ch/mare/springfundamentals/dependencyinjection/di_01/service/PostalService.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,12 @@ | ||
package ch.mare.springfundamentals.dependencyinjection.di_01.service; | ||
|
||
import ch.mare.springfundamentals.dependencyinjection.common.domain.MailingAddress; | ||
import org.springframework.stereotype.Component; | ||
|
||
//TODO: better naming? | ||
public class PostalService { | ||
|
||
public void sendLetter(MailingAddress mailingAddress) { | ||
System.out.println("A letter will be sent to " + mailingAddress); | ||
} | ||
} |