-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
30 lines (28 loc) · 1.23 KB
/
App.xaml.cs
File metadata and controls
30 lines (28 loc) · 1.23 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
using Autofac;
using Common;
using DevExpress.Mvvm;
using DevExpress.Mvvm.POCO;
using System;
using System.Windows;
namespace AutofacDI {
public partial class App : Application {
protected override void OnStartup(StartupEventArgs e) {
var builder = new ContainerBuilder();
builder.RegisterType(typeof(PersonStorage)).As(typeof(IDataStorage<Person>)).SingleInstance();
builder.RegisterType(ViewModelSource.GetPOCOType(typeof(DetailViewModel))).As(typeof(IDetailViewModel), typeof(DetailViewModel)).SingleInstance();
builder.RegisterType(ViewModelSource.GetPOCOType(typeof(CollectionViewModel))).As(typeof(CollectionViewModel));
IContainer container = builder.Build();
IocServiceProvider.Default.ConfigureServices(new AutofacServiceProvider(container));
base.OnStartup(e);
}
}
class AutofacServiceProvider : IServiceProvider {
readonly IContainer container;
public AutofacServiceProvider(IContainer container) {
this.container = container;
}
public object GetService(Type serviceType) {
return container.IsRegistered(serviceType) ? container.Resolve(serviceType) : null;
}
}
}