-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencyInjection(Using Property Injection).cs
More file actions
51 lines (47 loc) · 1.17 KB
/
DependencyInjection(Using Property Injection).cs
File metadata and controls
51 lines (47 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using ConsoleApp81;
using System;
/*
* Dependency Injection (DI) is a software design pattern that allow us to develop
* loosely coupled code . Di is a great way to reduce tight coupling between software
* components.
* Di is also enables us to better manage future changes and other
* complexity in our software.
*
*
* Suppose your client class needs to use two service classes.
* then the best you can do s to make your client class aware of abstraction.
*
*
*/
namespace ConsoleApp81
{
public interface INotificationAction
{
void ActOnNotification(string message);
}
internal class Test
{
private INotificationAction _task;
public void Notify(INotificationAction at, string message)
{
_task = at;
_task.ActOnNotification(message);
}
}
internal class EventLogWriter : INotificationAction
{
public void ActOnNotification(string message)
{
Console.WriteLine(message);
}
}
internal class Program
{
public static void Main()
{
var ewt = new EventLogWriter();
var test = new Test();
test.Notify(ewt, "Hello Harshal Raverkar");
}
}
}