UnityExt.cs 2.4 KB
Newer Older
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
using FlyADBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity;

namespace Flyad7_WPF
{
    public class UnityExt
    {

        public static UnityContainer Container;
        static UnityExt()
        {
            Init();
        }
        static void Init()
        {
            Container = new UnityContainer();

            Container.RegisterType<DebugAppParam>(
                new Unity.Lifetime.ContainerControlledLifetimeManager());

            Container.RegisterFactory<IFlyADClientAdv>((unity) =>
            {
28
                FlyAd2021 flyAd = new FlyAd2021();
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
                flyAd.IsReadParamFromDev = true;
                flyAd.Load();
                return flyAd;
            }, new Unity.Lifetime.ContainerControlledLifetimeManager());

            Container.RegisterFactory<AutoForwBackw>((unity) =>
            {
                var flyad = Container.Resolve<IFlyADClientAdv>();
                AutoForwBackw autofb = new AutoForwBackw(flyad);
                var param = unity.Resolve<DebugAppParam>();
                Misc.BindingOperations.SetBinding(param, nameof(param.FB_Pos1), autofb, nameof(autofb.FB_Pos1), Misc.BindingOperations.BindingMode.TwoWay);
                Misc.BindingOperations.SetBinding(param, nameof(param.FB_Pos2), autofb, nameof(autofb.FB_Pos2), Misc.BindingOperations.BindingMode.TwoWay);
                return autofb;
            }, new Unity.Lifetime.ContainerControlledLifetimeManager());

            Container.RegisterType<FlyADClientUI>(
                new Unity.Lifetime.ContainerControlledLifetimeManager());

            Container.RegisterType<AutoGetGridAdv>(
                new Unity.Lifetime.ContainerControlledLifetimeManager());

            Container.RegisterType<AutoSync>(
                new Unity.Lifetime.ContainerControlledLifetimeManager());

            Container.RegisterFactory<GridAdvVm>((unity) =>
            {
                var flyad = Container.Resolve<IFlyADClientAdv>();
                GridAdvVm gridAdvVm = new GridAdvVm(flyad);
                var param = unity.Resolve<DebugAppParam>();
                Misc.BindingOperations.SetBinding(param, nameof(param.HasGridAdv), gridAdvVm, nameof(gridAdvVm.HasGridAdv), Misc.BindingOperations.BindingMode.TwoWay);
                return gridAdvVm;
            }, new Unity.Lifetime.ContainerControlledLifetimeManager());
        }

    }
}