Esempio n. 1
0
        public void EnsureInitialized(Context applicationContext)
        {
            if (MvxSimpleIoCContainer.Instance != null)
            {
                return;
            }

            var ioc = MvxSimpleIoCContainer.Initialize();

            ioc.RegisterSingleton <IMvxTrace>(new MvxDebugOnlyTrace());
            MvxTrace.Initialize();

            ioc.RegisterSingleton <IMvxAndroidGlobals>(new AndroidGlobals(applicationContext));

            var builder = new MvxAndroidBindingBuilder();

            builder.DoRegistration();

            var viewCache = ioc.Resolve <IMvxTypeCache <View> >();

            viewCache.AddAssembly(typeof(View).Assembly);

            var namespaces = ioc.Resolve <IMvxNamespaceListViewTypeResolver>();

            namespaces.Add("Android.Views");
            namespaces.Add("Android.Widget");
            namespaces.Add("Android.Webkit");
        }
Esempio n. 2
0
 public static void RegisterTypes()
 {
     MvxSimpleIoCContainer.Initialize();
     Mvx.RegisterType <ILoginService, LoginService> ();
     Mvx.RegisterType <IStopWatchWrapper, StopWatchWrapper> ();
     Mvx.RegisterType <IApiService, ApiService> ();
 }
        public void TryResolve_WithAttrInjection_AttrMarkedProperiesGetInjected()
        {
            MvxSingleton.ClearAllSingletons();
            var options = new MvxIocOptions
            {
                PropertyInjectorOptions = new MvxPropertyInjectorOptions()
                {
                    InjectIntoProperties = MvxPropertyInjection.MvxInjectInterfaceProperties
                }
            };
            var instance = MvxSimpleIoCContainer.Initialize(options);

            Mvx.RegisterType <IA, A>();
            Mvx.RegisterType <IB, B>();
            Mvx.RegisterType <IC, C>();

            IA  a;
            var result = Mvx.TryResolve(out a);

            Assert.IsTrue(result);
            Assert.IsNotNull(a);
            Assert.IsInstanceOf <A>(a);
            var castA = (A)a;

            Assert.IsNotNull(castA.B);
            Assert.IsInstanceOf <B>(castA.B);
            Assert.IsNull(castA.C);
            Assert.IsNull(castA.BNever);
            Assert.IsNull(castA.CNever);
        }
Esempio n. 4
0
        public static void Check()
        {
            if (_checked)
            {
                return;
            }

            _checked = true;

#if WINDOWS_WPF
            if (!(bool)DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)
            {
                return;
            }
#endif
#if WINDOWS_COMMON
            if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return;
            }
#endif

            if (MvxSingleton <IMvxIoCProvider> .Instance == null)
            {
                var iocProvider = MvxSimpleIoCContainer.Initialize();
                Mvx.RegisterSingleton(iocProvider);
            }

            if (!Mvx.CanResolve <IMvxBindingParser>())
            {
                var builder = new MvxWindowsBindingBuilder(MvxWindowsBindingBuilder.BindingType.MvvmCross);
                builder.DoRegistration();
            }
        }
Esempio n. 5
0
        public static void Check()
        {
            if (_checked)
            {
                return;
            }

            _checked = true;

            // if Application.Current == null Forms is in design mode
            if (Application.Current != null)
            {
                return;
            }

            if (MvxSingleton <IMvxIoCProvider> .Instance == null)
            {
                var iocProvider = MvxSimpleIoCContainer.Initialize();
                Mvx.RegisterSingleton(iocProvider);
            }

            if (!Mvx.CanResolve <IMvxBindingParser>())
            {
                //We might want to look into returning the platform specific Forms binder
                var builder = new MvxBindingBuilder();
                builder.DoRegistration();
            }
        }
        public static void Check()
        {
            if (_checked)
            {
                return;
            }

            _checked = true;

            if (!DesignMode.DesignModeEnabled)
            {
                return;
            }

            if (MvxSingleton <IMvxIoCProvider> .Instance == null)
            {
                var iocProvider = MvxSimpleIoCContainer.Initialize();
                Mvx.RegisterSingleton(iocProvider);
            }

            if (!Mvx.CanResolve <IMvxBindingParser>())
            {
                var builder = new MvxWindowsBindingBuilder(MvxWindowsBindingBuilder.BindingType.MvvmCross);
                builder.DoRegistration();
            }
        }
        public static void Initialize()
        {
            MvxSimpleIoCContainer.Initialize();

            Mvx.LazyConstructAndRegisterSingleton <INavigationMenuService <Activity>, NavigationMenuService>();
            Mvx.RegisterSingleton(typeof(IStringLookup), new StringLookup(this.ApplicationContext));
        }
Esempio n. 8
0
        public void EnsureInitialized(Context context)
        {
            if (MvxSimpleIoCContainer.Instance != null)
            {
                return;
            }

            ApplicationContext = context;

            MvxSimpleIoCContainer.Initialize();

            Mvx.RegisterSingleton <IMvxAndroidGlobals>(this);

            var plugin = new MvxFilePluginManager(".Droid", ".dll");

            Mvx.RegisterSingleton <IMvxPluginManager>(plugin);

            var builder = new MvxAndroidBindingBuilder();

            builder.DoRegistration();

            var viewCache = Mvx.Resolve <IMvxTypeCache <View> >();

            viewCache.AddAssembly(typeof(Android.Widget.LinearLayout).Assembly);

            var valueConverterRegistry = Mvx.Resolve <IMvxValueConverterRegistry>();

            valueConverterRegistry.AddOrOverwrite("TheLengthConverter", new LengthValueConverter());

            var locationBootstrap = new LocationPluginBootstrap();

            locationBootstrap.Run();
        }
        public void EnsureInitialized(Context applicationContext)
        {
            if (MvxSimpleIoCContainer.Instance != null)
            {
                return;
            }

            var ioc = MvxSimpleIoCContainer.Initialise();

            ioc.RegisterSingleton <IMvxPluginManager>(new MvxFilePluginManager(".Droid", ".dll"));

            ioc.RegisterSingleton <IMvxAndroidGlobals>(new AndroidGlobals(applicationContext, GetType().Namespace));

            var topActivity = new AndroidTopActivity();

            ioc.RegisterSingleton <ITopActivity>(topActivity);
            ioc.RegisterSingleton <IMvxMainThreadDispatcher>(topActivity);

            var builder = new MvxAndroidBindingBuilder();

            builder.DoRegistration();

            var viewCache = ioc.Resolve <IMvxTypeCache <View> >();

            viewCache.AddAssembly(typeof(View).Assembly);

            var namespaces = ioc.Resolve <IMvxNamespaceListViewTypeResolver>();

            namespaces.Add("Android.Views");
            namespaces.Add("Android.Widget");
            namespaces.Add("Android.Webkit");
        }
        public void EnsureInit(IMvxAndroidGlobals androidGlobals)
        {
            if (MvxSimpleIoCContainer.Instance != null)
            {
                return;
            }

            MvxSimpleIoCContainer.Initialize();

            Mvx.RegisterSingleton <IMvxTrace>(new MvxDebugTrace());
            MvxTrace.Initialize();

            Mvx.RegisterSingleton <IMvxAndroidGlobals>(androidGlobals);

            new MvxAndroidBindingBuilder().DoRegistration();

            var viewCache = Mvx.Resolve <IMvxTypeCache <View> >();

            viewCache.AddAssembly(typeof(View).Assembly);

            var namespaces = Mvx.Resolve <IMvxNamespaceListViewTypeResolver>();

            namespaces.Add("Android.Views");
            namespaces.Add("Android.Widget");
            namespaces.Add("Android.Webkit");
        }
Esempio n. 11
0
        public override void OnCreate()
        {
            MvxSimpleIoCContainer.Initialize();
            Mvx.RegisterType <IPlatform, DroidPlatform> ();
            Mvx.RegisterType <ISettings, DroidSettings> ();

            base.OnCreate();
        }
Esempio n. 12
0
 public static void Initialize()
 {
     BlobCache.ApplicationName = "MahTestApp";
     BlobCache.EnsureInitialized();
     MvxSimpleIoCContainer.Initialize();
     Mvx.RegisterSingleton <IBlobCache>(() => BlobCache.LocalMachine);
     Mvx.RegisterType <IPlatform, ApplePlatform> ();
     Mvx.RegisterType <ISettings, AppleSettings> ();
 }
Esempio n. 13
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            DispatcherHelper.Initialize();

            ServiceLocator.MessageService        = new MessageService();
            ServiceLocator.LiveTileNotifyService = new LiveTileNotifyService();
            ServiceLocator.NavigationService     = new NavigationService();
            ServiceLocator.AzureMobileService    = new AzureMobileService();
            ServiceLocator.ResourceFileService   = new ResourceFileService();

            //Using MVVM Cross Container
            var iocProvider = MvxSimpleIoCContainer.Initialise();

            Mvx.RegisterSingleton <IMvxFileStore>(new MvxWindowsStoreBlockingFileStore());

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            //if (rootFrame.Content == null)
            //{
            //    // When the navigation stack isn't restored navigate to the first page,
            //    // configuring the new page by passing required information as a navigation
            //    // parameter
            //    if (!rootFrame.Navigate(typeof(ItemsShowcaseView), args.Arguments))
            //    {
            //        throw new Exception("Failed to create initial page");
            //    }
            //}

            //MVVMCross setup
            var setup = new Setup(rootFrame);

            setup.Initialize();

            //MVVMCross setup
            var start = Mvx.Resolve <IMvxAppStart>();

            start.Start();

            // Ensure the current window is active
            Window.Current.Activate();
        }
Esempio n. 14
0
        public void Non_generic_RegisterType_with_constructor_throws_if_constructor_returns_incompatible_value()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxSimpleIoCContainer.Initialize();

            instance.RegisterType(typeof(IC), () => 36);

            var c1 = Mvx.Resolve <IC>();
        }
Esempio n. 15
0
        public static void ClassInitialize(TestContext t)
        {
            ServiceLocator.AzureMobileService  = new AzureMobileService();
            ServiceLocator.ResourceFileService = new TestResourceFileService();
            ServiceLocator.MessageService      = new TestMessageService();

            var iocProvider = MvxSimpleIoCContainer.Initialize();

            Mvx.RegisterSingleton <IMvxFileStore>(new MvxWpfFileStore());
        }
Esempio n. 16
0
        public static void Initialize()
        {
            if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
            {
                return;
            }
            var iocProvider = MvxSimpleIoCContainer.Initialize();

            Mvx.RegisterSingleton(iocProvider);
        }
Esempio n. 17
0
 protected virtual void ClearAll()
 {
     // fake set up of the IoC
     MvxSingleton.ClearAllSingletons();
     _ioc = MvxSimpleIoCContainer.Initialise();
     _ioc.RegisterSingleton(_ioc);
     _ioc.RegisterSingleton <IMvxTrace>(new TestTrace());
     MvxTrace.Initialize();
     MvxBindingStatics.ClearCaches();
     AdditionalSetup();
 }
Esempio n. 18
0
        public static void Register()
        {
            MvxSimpleIoCContainer.Initialize();

            Mvx.ConstructAndRegisterSingleton <IUserDialogService, UserDialogService>();
            Mvx.ConstructAndRegisterSingleton <IGitHubDataProvider, GitHubDataProvider>();
            Mvx.ConstructAndRegisterSingleton <INavigationService, NavigationService>();

            Mvx.RegisterType <IRepositoriesViewModel, RepositoriesViewModel>();
            Mvx.RegisterType <IRepositoryDetailsViewModel, RepositoryDetailsViewModel>();
        }
Esempio n. 19
0
        public void Non_generic_RegisterType_with_constructor_throws_if_constructor_returns_incompatible_reference()
        {
            MvxSingleton.ClearAllSingletons();
            var instance = MvxSimpleIoCContainer.Initialize();

            instance.RegisterType(typeof(IC), () => "Fail");

            Assert.Throws <MvxIoCResolveException>(() => {
                var c1 = Mvx.Resolve <IC>();
            });
        }
Esempio n. 20
0
        public static void ResetContext()
        {
            MvxSingleton.ClearAllSingletons();
            var ioc = MvxSimpleIoCContainer.Initialize(null);

            ioc.RegisterSingleton(ioc);
            ioc.RegisterSingleton <IMvxTrace>(new UnitTestTrace());
            MvxSingletonCache.Initialize();
            ioc.RegisterSingleton <IMvxSettings>(new MvxSettings());
            MvxTrace.Initialize();
        }
Esempio n. 21
0
        public override void OnCreate()
        {
            BlobCache.ApplicationName = "MahTestApp";
            BlobCache.EnsureInitialized();
            MvxSimpleIoCContainer.Initialize();
            Mvx.RegisterSingleton <IBlobCache>(() => BlobCache.LocalMachine);
            Mvx.RegisterType <IPlatform, DroidPlatform> ();
            Mvx.RegisterType <ISettings, DroidSettings> ();

            base.OnCreate();
        }
Esempio n. 22
0
 protected virtual void ClearAll()
 {
     // fake set up of the IoC
     MvxSingleton.ClearAllSingletons();
     this._ioc = MvxSimpleIoCContainer.Initialize(this.CreateIocOptions());
     this._ioc.RegisterSingleton(this._ioc);
     this._ioc.RegisterSingleton <IMvxTrace>(new TestTrace());
     InitializeSingletonCache();
     this.InitializeMvxSettings();
     MvxTrace.Initialize();
     this.AdditionalSetup();
 }
Esempio n. 23
0
 protected void ClearAll()
 {
     // fake set up of the IoC
     MvxSingleton.ClearAllSingletons();
     _ioc = MvxSimpleIoCContainer.Initialise();
     _ioc.RegisterSingleton(_ioc);
     _ioc.RegisterSingleton <IMvxTrace>(new TestTrace());
     RegisterAdditionalSingletons();
     InitialiseSingletonCache();
     InitialiseMvxSettings();
     MvxTrace.Initialize();
 }
Esempio n. 24
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            ServiceLocator.MessageService        = new MessageService();
            ServiceLocator.LiveTileNotifyService = new LiveTileNotifyService();
            ServiceLocator.NavigationService     = new XPlatformCloudKit.Services.NavigationService();
            ServiceLocator.AzureMobileService    = new AzureMobileService();
            ServiceLocator.ResourceFileService   = new ResourceFileService();

            //Using MVVM Cross IOCContainer
            var iocProvider = MvxSimpleIoCContainer.Initialise();

            Mvx.RegisterSingleton <IMvxFileStore>(new MvxIsolatedStorageFileStore());
        }
        protected MvxDesignTimeHelper()
        {
            if (!IsInDesignTool)
            {
                return;
            }

            if (MvxSingleton <IMvxIoCProvider> .Instance == null)
            {
                var iocProvider = MvxSimpleIoCContainer.Initialize();
                Mvx.RegisterSingleton(iocProvider);
            }
        }
Esempio n. 26
0
        private static void Configurate()
        {
            ////здесь будет конфигурироваться DI контейнер
            MvxSimpleIoCContainer.Initialize();


            Mvx.RegisterSingleton <IOrderService>(new OrderService());
            Mvx.RegisterSingleton <IUserService>(new UserService());
            Mvx.RegisterSingleton <IOrderHubService>(new OrderHubService());

            Mvx.ConstructAndRegisterSingleton <IUserController, UserController>();
            Mvx.ConstructAndRegisterSingleton <IOrderController, OrderController>();
        }
Esempio n. 27
0
        public static void Initialize(Context applicationContext)
        {
            MvxSimpleIoCContainer.Initialize();

            Mvx.LazyConstructAndRegisterSingleton <INavigationMenuService <Fragment>, NavigationMenuService>();
            Mvx.RegisterSingleton(typeof(IStringLookupService), new StringLookupService(applicationContext));
            Mvx.RegisterSingleton(typeof(IVersionInfo), new VersionInfoService(applicationContext));
            Mvx.LazyConstructAndRegisterSingleton <ILoggingService, FileLoggingService>();
            Mvx.LazyConstructAndRegisterSingleton <IFileHelper, FileHelper>();
            Mvx.LazyConstructAndRegisterSingleton <IJobsService, JobsService>();
            Mvx.LazyConstructAndRegisterSingleton <IITunesDataService, ITunesDataService>();
            Mvx.LazyConstructAndRegisterSingleton <ICreateHttpClientHelper, AndroidConnectionHandlerCreator>();
        }
Esempio n. 28
0
        public void EnsureInitialized(Context applicationContext)
        {
            if (MvxSimpleIoCContainer.Instance != null)
            {
                return;
            }

            var ioc = MvxSimpleIoCContainer.Initialise();

            ioc.RegisterSingleton <IMvxPluginManager>(new MvxFilePluginManager(".Droid", ".dll"));

            ioc.RegisterSingleton <IMvxAndroidGlobals>(new AndroidGlobals(applicationContext, GetType().Namespace));
        }
Esempio n. 29
0
        public void EnsureInit()
        {
            if (MvxSimpleIoCContainer.Instance != null)
            {
                return;
            }

            var ioc = MvxSimpleIoCContainer.Initialize();

            var builder = new MvxTouchBindingBuilder();

            builder.DoRegistration();
        }
        public static void Resolves_unsuccessfully_when_registered_open_generic_with_one_generic_parameter_that_was_not_registered()
        {
            var instance = MvxSimpleIoCContainer.Initialize();

            ((MvxSimpleIoCContainer)instance).CleanAllResolvers();

            IOG <C2> toResolve = null;

            var isResolved = Mvx.TryResolve <IOG <C2> >(out toResolve);

            Assert.IsFalse(isResolved);
            Assert.IsNull(toResolve);
        }