FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
core/Examples/DependencyInjection/Program.cs at master · KY-Programming/core · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
KY-Programming
/
core
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
core
/
Examples
/
DependencyInjection
/
Program.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (30 loc) · 1.1 KB
Breadcrumbs
core
/
Examples
/
DependencyInjection
/
Program.cs
Copy path
File metadata and controls
38 lines (30 loc) · 1.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using
System
;
using
DependencyInjection
.
Consumers
;
using
DependencyInjection
.
Services
;
using
KY
.
Core
.
Dependency
;
namespace
DependencyInjection
{
internal
class
Program
{
private
static
void
Main
(
string
[
]
args
)
{
DependencyResolver
resolver
=
new
DependencyResolver
(
)
;
// Bind a type to an interface
resolver
.
Bind
<
IFirstService
>
(
)
.
To
<
FirstService
>
(
)
;
// Bind a type as ans singleton
resolver
.
Bind
<
SecondService
>
(
)
.
ToSingleton
(
)
;
// Create an instance of an object with dependency injection
Consumer1
consumer1
=
resolver
.
Create
<
Consumer1
>
(
)
;
consumer1
.
Run
(
)
;
// Resolve an instance by hand
resolver
.
Get
<
SecondService
>
(
)
.
Write
(
)
;
// Resolve by type
Consumer2
consumer2
=
(
Consumer2
)
resolver
.
Create
(
typeof
(
Consumer2
)
)
;
consumer2
.
Run
(
)
;
// Resolve with additional parameters
Consumer3
consumer3
=
resolver
.
Create
<
Consumer3
>
(
"abcdefg"
)
;
consumer3
.
Run
(
)
;
Console
.
ReadLine
(
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL