Skip to content

Commit

Permalink
DependencyInject
Browse files Browse the repository at this point in the history
  • Loading branch information
XuanThuLab committed Aug 21, 2020
1 parent a4a4257 commit f66749c
Show file tree
Hide file tree
Showing 38 changed files with 1,008 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/car_horn_di_interface.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
42 changes: 42 additions & 0 deletions CS027_Dependencyinjection/car_horn_di_interface/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/car_horn_di_interface.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/car_horn_di_interface.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/car_horn_di_interface.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
28 changes: 28 additions & 0 deletions CS027_Dependencyinjection/car_horn_di_interface/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace car_horn_di_interface {
public interface IHorn {
void Beep ();
}
public class Car {
IHorn horn; // IHorn (Interface) là một Dependecy của Car
public Car (IHorn horn) => this.horn = horn; // Inject từ hàm tạo
public void Beep () => horn.Beep ();
}
public class HeavyHorn : IHorn {
public void Beep () => Console.WriteLine ("(kêu to lắm) BEEP BEEP BEEP ...");
}

public class LightHorn : IHorn {
public void Beep () => Console.WriteLine ("(kêu bé lắm) beep bep bep ...");
}
class Program {
static void Main (string[] args) {
Car car1 = new Car (new HeavyHorn ());
car1.Beep (); // (kểu to lắm) BEEP BEEP BEEP ...

Car car2 = new Car (new LightHorn ());
car2.Beep (); // (kểu bé lắm) beep bep bep ...
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
27 changes: 27 additions & 0 deletions CS027_Dependencyinjection/car_horn_nodi/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/car-horn-nodi.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
42 changes: 42 additions & 0 deletions CS027_Dependencyinjection/car_horn_nodi/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/car-horn-nodi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/car-horn-nodi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/car-horn-nodi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
16 changes: 16 additions & 0 deletions CS027_Dependencyinjection/car_horn_nodi/CarAndHorn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace car_horn_nodi {
public class Horn {
public void Beep () => Console.WriteLine ("Beep - beep - beep ...");
}

public class Car {
public void Beep () {
// chức năng Beep xây dựng có định với Horn
// tự tạo đối tượng horn (new) và dùng nó
Horn horn = new Horn ();
horn.Beep ();
}
}
}
14 changes: 14 additions & 0 deletions CS027_Dependencyinjection/car_horn_nodi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace car_horn_nodi
{
class Program
{
static void Main(string[] args)
{
var car = new Car();
car.Beep(); // Beep - beep - beep ...

}
}
}
9 changes: 9 additions & 0 deletions CS027_Dependencyinjection/car_horn_nodi/car_horn_nodi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>car_horn_nodi</RootNamespace>
</PropertyGroup>

</Project>
27 changes: 27 additions & 0 deletions CS027_Dependencyinjection/car_horn_nodi_update/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/car-horn-nodi.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
42 changes: 42 additions & 0 deletions CS027_Dependencyinjection/car_horn_nodi_update/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/car-horn-nodi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/car-horn-nodi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/car-horn-nodi.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
}
17 changes: 17 additions & 0 deletions CS027_Dependencyinjection/car_horn_nodi_update/CarAndHorn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace car_horn_nodi_update {
public class Horn {
int level; // độ lớn của còi xe
public Horn (int level) => this.level = level; // thêm khởi tạo level
public void Beep () => Console.WriteLine ($"(level {level}) Beep - beep - beep ...");
}

public class Car {
public void Beep () {
// Tạo Horn phải cung cập level
Horn horn = new Horn (10);
horn.Beep ();
}
}
}
14 changes: 14 additions & 0 deletions CS027_Dependencyinjection/car_horn_nodi_update/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace car_horn_nodi_update
{
class Program
{
static void Main(string[] args)
{
var car = new Car();
car.Beep(); // Beep - beep - beep ...

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>car_horn_nodi_update</RootNamespace>
</PropertyGroup>

</Project>
27 changes: 27 additions & 0 deletions CS027_Dependencyinjection/car_horn_with_di/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/car-horn-nodi.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
Loading

0 comments on commit f66749c

Please sign in to comment.