-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIocSandbox.linq
More file actions
69 lines (56 loc) · 1.7 KB
/
IocSandbox.linq
File metadata and controls
69 lines (56 loc) · 1.7 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<Query Kind="Program">
<NuGetReference>Prism.Core</NuGetReference>
<NuGetReference>Prism.DryIoc</NuGetReference>
<NuGetReference>Prism.Wpf</NuGetReference>
<Namespace>Prism.Ioc</Namespace>
<Namespace>Prism.DryIoc</Namespace>
<Namespace>System.Windows</Namespace>
<Namespace>DryIoc</Namespace>
</Query>
void Main()
{
var myApp = new App();
var serviceA = App.AppContainer.Resolve<IServiceA>();
serviceA.SayHello().Dump("Service A Method");
if (serviceA is IServiceB serviceB)
{
serviceB.SayGoodbye().Dump("Service B Method");
}
}
// You can define other methods, fields, classes and namespaces here
public class App: PrismApplication
{
public static IContainer AppContainer { get; set; }
public App() {
OnStartup(null);
}
protected override void OnStartup(StartupEventArgs args)
{
base.OnStartup(args);
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.AddMyNewModulesServices();
AppContainer = containerRegistry.GetContainer();
}
protected override Window CreateShell() { return new Window(); }
}
public static class MyNewModuleContainerExtensions
{
public static IContainerRegistry AddMyNewModulesServices(this IContainerRegistry registry)
{
registry.Register<IServiceA, ServiceAbc>();
registry.Register<IServiceB, ServiceAbc>();
registry.Register<IServiceC, ServiceAbc>();
return registry;
}
}
public interface IServiceA { string SayHello(); }
public interface IServiceB { string SayGoodbye(); }
public interface IServiceC { }
public class ServiceAbc : IServiceA, IServiceB, IServiceC
{
public ServiceAbc() {}
public string SayHello() { return "Hello World"; }
public string SayGoodbye() { return "Goodbye!"; }
}