Dreamine.MVVM.Core
1.0.13
중요: 자동 등록된 타입은 기본적으로 Singleton으로 등록됩니다. 따라서 자동 발견된 ViewModel, Model, Event, Manager는 애플리케이션이 별도 수명으로 명시 등록하지 않는 한 반복 해석 시 동일 인스턴스를 유지합니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
DMContainer.cs
이 파일의 문서화 페이지로 가기
1
using
System;
2
using
System.Reflection;
3
using
Dreamine.MVVM.Core.DependencyInjection
;
4
using
Dreamine.MVVM.Interfaces.DependencyInjection;
5
6
namespace
Dreamine.MVVM.Core
7
{
16
public
static
partial class
DMContainer
17
{
26
private
static
readonly
object
SyncRoot
=
new
();
35
private
static
IServiceContainer
Container
=
CreateDefaultContainer
();
36
37
// Self-registers IServiceResolver so that ViewManager(IServiceResolver) and other
38
// constructor-injected types can be resolved by DreamineContainer without an
39
// explicit registration call from application startup code.
56
private
static
DreamineContainer
CreateDefaultContainer
()
57
{
58
var c =
new
DreamineContainer
();
59
c.RegisterSingleton<IServiceResolver>(c);
60
return
c;
61
}
62
79
internal
static
IServiceRegistry GetRegistry()
80
{
81
lock (
SyncRoot
) {
return
Container
; }
82
}
83
100
public
static
IServiceResolver
GetResolver
()
101
{
102
lock (
SyncRoot
) {
return
Container
; }
103
}
104
105
122
public
static
void
SetContainer
(IServiceContainer container)
123
{
124
ArgumentNullException.ThrowIfNull(container);
125
126
lock (
SyncRoot
)
127
{
128
Container
= container;
129
}
130
}
131
140
public
static
void
Reset
()
141
{
142
IServiceContainer previous;
143
144
lock (
SyncRoot
)
145
{
146
previous =
Container
;
147
Container
=
CreateDefaultContainer
();
148
}
149
150
(previous as IDisposable)?.Dispose();
151
}
152
169
public
static
void
Register<TImplementation>
()
170
where TImplementation : class
171
{
172
lock (
SyncRoot
)
173
{
174
Container
.Register<TImplementation>();
175
}
176
}
177
202
public
static
void
Register<TService, TImplementation>
()
203
where TService : class
204
where TImplementation : class, TService
205
{
206
lock (
SyncRoot
)
207
{
208
Container
.Register<TService, TImplementation>();
209
}
210
}
211
236
public
static
void
Register<TService>
(Func<TService> factory)
237
where TService :
class
238
{
239
lock (
SyncRoot
)
240
{
241
Container
.Register(factory);
242
}
243
}
244
269
public
static
void
RegisterSingleton<TService>
(TService instance)
270
where TService :
class
271
{
272
lock (
SyncRoot
)
273
{
274
Container
.RegisterSingleton(instance);
275
}
276
}
277
294
public
static
void
RegisterSingleton<TImplementation>
()
295
where TImplementation : class
296
{
297
lock (
SyncRoot
)
298
{
299
Container
.RegisterSingleton<TImplementation>();
300
}
301
}
302
327
public
static
void
RegisterSingleton<TService, TImplementation>
()
328
where TService : class
329
where TImplementation : class, TService
330
{
331
lock (
SyncRoot
)
332
{
333
Container
.RegisterSingleton<TService, TImplementation>();
334
}
335
}
336
361
public
static
TService
Resolve<TService>
()
362
where TService : class
363
{
364
lock (
SyncRoot
)
365
{
366
return
Container
.Resolve<TService>();
367
}
368
}
369
394
public
static
object
Resolve
(Type type)
395
{
396
ArgumentNullException.ThrowIfNull(type);
397
398
lock (
SyncRoot
)
399
{
400
return
Container
.Resolve(type);
401
}
402
}
403
436
public
static
bool
TryResolve<TService>
(out TService? result)
437
where TService :
class
438
{
439
try
440
{
441
lock (
SyncRoot
)
442
{
443
result =
Container
.Resolve<TService>();
444
return
true
;
445
}
446
}
447
catch
(InvalidOperationException)
448
{
449
result =
null
;
450
return
false
;
451
}
452
}
453
478
[System.Obsolete(
"Use DreamineAutoRegistrar.RegisterAll(rootAssembly, DMContainer) instead."
)]
479
public
static
void
AutoRegisterAll
(Assembly rootAssembly)
480
{
481
DreamineAutoRegistrar
.
RegisterAll
(rootAssembly,
Container
);
482
}
483
508
public
static
bool
IsRegistered<TService>
()
509
{
510
lock (
SyncRoot
)
511
{
512
return
Container
.IsRegistered(typeof(TService));
513
}
514
}
515
540
public
static
bool
IsRegistered
(Type serviceType)
541
{
542
ArgumentNullException.ThrowIfNull(serviceType);
543
544
lock (
SyncRoot
)
545
{
546
return
Container
.IsRegistered(serviceType);
547
}
548
}
549
}
550
}
Dreamine.MVVM.Core
Definition
AssemblyTypeScanner.cs:8
Dreamine.MVVM.Core.DependencyInjection
Definition
ConstructorActivator.cs:6
Dreamine.MVVM.Core.DependencyInjection.DreamineContainer
Definition
DreamineContainer.cs:17
Dreamine.MVVM.Core.DMContainer
Definition
DMContainer.cs:17
Dreamine.MVVM.Core.DMContainer.CreateDefaultContainer
static DreamineContainer CreateDefaultContainer()
Definition
DMContainer.cs:56
Dreamine.MVVM.Core.DMContainer.IsRegistered
static bool IsRegistered(Type serviceType)
Definition
DMContainer.cs:540
Dreamine.MVVM.Core.DMContainer.SyncRoot
static readonly object SyncRoot
Definition
DMContainer.cs:26
Dreamine.MVVM.Core.DMContainer.AutoRegisterAll
static void AutoRegisterAll(Assembly rootAssembly)
Definition
DMContainer.cs:479
Dreamine.MVVM.Core.DMContainer.Container
static IServiceContainer Container
Definition
DMContainer.cs:35
Dreamine.MVVM.Core.DMContainer.RegisterSingleton< TService, TImplementation >
static void RegisterSingleton< TService, TImplementation >()
Definition
DMContainer.cs:327
Dreamine.MVVM.Core.DMContainer.RegisterSingleton< TService >
static void RegisterSingleton< TService >(TService instance)
Definition
DMContainer.cs:269
Dreamine.MVVM.Core.DMContainer.IsRegistered< TService >
static bool IsRegistered< TService >()
Definition
DMContainer.cs:508
Dreamine.MVVM.Core.DMContainer.RegisterSingleton< TImplementation >
static void RegisterSingleton< TImplementation >()
Definition
DMContainer.cs:294
Dreamine.MVVM.Core.DMContainer.Register< TImplementation >
static void Register< TImplementation >()
Definition
DMContainer.cs:169
Dreamine.MVVM.Core.DMContainer.SetContainer
static void SetContainer(IServiceContainer container)
Definition
DMContainer.cs:122
Dreamine.MVVM.Core.DMContainer.Resolve< TService >
static TService Resolve< TService >()
Definition
DMContainer.cs:361
Dreamine.MVVM.Core.DMContainer.Register< TService >
static void Register< TService >(Func< TService > factory)
Definition
DMContainer.cs:236
Dreamine.MVVM.Core.DMContainer.Reset
static void Reset()
Definition
DMContainer.cs:140
Dreamine.MVVM.Core.DMContainer.GetResolver
static IServiceResolver GetResolver()
Definition
DMContainer.cs:100
Dreamine.MVVM.Core.DMContainer.Register< TService, TImplementation >
static void Register< TService, TImplementation >()
Definition
DMContainer.cs:202
Dreamine.MVVM.Core.DMContainer.Resolve
static object Resolve(Type type)
Definition
DMContainer.cs:394
Dreamine.MVVM.Core.DMContainer.TryResolve< TService >
static bool TryResolve< TService >(out TService? result)
Definition
DMContainer.cs:436
Dreamine.MVVM.Core.DreamineAutoRegistrar
Definition
DreamineAutoRegistrar.cs:16
Dreamine.MVVM.Core.DreamineAutoRegistrar.RegisterAll
static void RegisterAll(Assembly rootAssembly, IServiceRegistry registry)
Definition
DreamineAutoRegistrar.cs:53
DMContainer.cs
다음에 의해 생성됨 :
1.17.0