61 lines
1.3 KiB
C#
61 lines
1.3 KiB
C#
using Autofac;
|
|
using MAX.Common.WPF.Converters;
|
|
using MAX.Common.WPF.Utilities;
|
|
using MAX.Core;
|
|
using MAX.Core.Autofac;
|
|
using MAX.Framework.Interfaces;
|
|
using Store.Management.Api;
|
|
using Store.Management.Framework.Extensions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Store.Management.Framework
|
|
{
|
|
internal class Startup : IStartup
|
|
{
|
|
public int Priority => IntPriority.High;
|
|
|
|
public void Initialize()
|
|
{
|
|
EnumDisplayConverter.EnumDisplayManager = new EnumDisplayManagerWPF(null);
|
|
}
|
|
|
|
public void Register(ContainerBuilder builder)
|
|
{
|
|
var client = new StoreApiClient(new ApiClientOptions
|
|
{
|
|
BaseUrl = new Uri("http://localhost:14312/api/")
|
|
});
|
|
builder.Register(_ => client).SingleInstance().PreserveExistingDefaults();
|
|
|
|
DISource.Resolver = Resolve;
|
|
}
|
|
protected virtual object? Resolve(Type? type, string? name)
|
|
{
|
|
if (type == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (IocManager.Container is not null)
|
|
{
|
|
if (name != null)
|
|
{
|
|
if (IocManager.Container.IsRegisteredWithName(name, type))
|
|
{
|
|
return IocManager.Container.ResolveNamed(name, type);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
return IocManager.Resolve(type);
|
|
}
|
|
|
|
return Activator.CreateInstance(type);
|
|
}
|
|
}
|
|
}
|