示例#1
0
        /// <summary> Run library initialization logic. </summary>
        public static CompositionRoot Run()
        {
            const string fatalCategoryName = "Fatal";

            // create default container which should not be exposed outside to avoid Service Locator pattern.
            var container = new Container();

            // create trace to log important messages
            var trace = new UnityLogTrace();

            // utymap requires some files/directories to be precreated.
            InstallationApi.EnsureFileHierarchy(trace);

            // setup RX configuration.
            UnityScheduler.SetDefaultForUnity();

            // subscribe to unhandled exceptions in RX
            MainThreadDispatcher.RegisterUnhandledExceptionCallback(ex => trace.Error(fatalCategoryName, ex, "Unhandled exception"));

            try
            {
                var compositionRoot = BuildCompositionRoot(container, trace);
                SubscribeOnMapData(compositionRoot, trace);
                return(compositionRoot);
            }
            catch (Exception ex)
            {
                trace.Error(fatalCategoryName, ex, "Cannot setup object graph.");
                throw;
            }
        }
示例#2
0
        /// <summary> Run library initialization logic. </summary>
        public static CompositionRoot Run(Action <IContainer, IConfigSection> action)
        {
            const string fatalCategoryName = "Fatal";

            // create trace for logging and set its level
            var trace = new UnityLogTrace();

            trace.Level = DefaultTrace.TraceLevel.Debug;

            // utymap requires some files/directories to be precreated.
            InstallationApi.EnsureFileHierarchy(trace);

            // setup RX configuration.
            UnityScheduler.SetDefaultForUnity();

            // subscribe to unhandled exceptions in RX
            MainThreadDispatcher.RegisterUnhandledExceptionCallback(ex => trace.Error(fatalCategoryName, ex, "Unhandled exception"));

            try
            {
                var compositionRoot = BuildCompositionRoot(action, trace);
                SubscribeOnMapData(compositionRoot, trace);
                return(compositionRoot);
            }
            catch (Exception ex)
            {
                trace.Error(fatalCategoryName, ex, "Cannot setup object graph.");
                throw;
            }
        }
示例#3
0
        public void InitializeFramework(ConfigBuilder configBuilder, Action <CompositionRoot> initAction)
        {
            IsInitialized = false;

            // Need to dispose all previously used components as we're going to create new ones.
            if (_container != null)
            {
                _container.Dispose();
            }

            // create default container which should not be exposed outside to avoid Service Locator pattern.
            _container = new Container();

            // create trace to log important messages
            _trace = new DebugConsoleTrace();

            // UtyMap requires some files/directories to be precreated.
            InstallationApi.EnsureFileHierarchy(_trace);

            // Setup RX configuration.
            UnityScheduler.SetDefaultForUnity();

            // subscribe to unhandled exceptions in RX
            MainThreadDispatcher.RegisterUnhandledExceptionCallback(ex =>
                                                                    _trace.Error(FatalCategoryName, ex, "Unhandled exception"));

            try
            {
                var config = configBuilder
                             .SetStringIndex("Index/")
                             .SetSpatialIndex("Index/")
                             .Build();

                // create entry point for utymap functionallity
                _compositionRoot = new CompositionRoot(_container, config)
                                   .RegisterAction((c, _) => c.RegisterInstance <ITrace>(_trace))
                                   .RegisterAction((c, _) => c.Register(Component.For <IPathResolver>().Use <DemoPathResolver>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <IModelBuilder>().Use <DemoModelBuilder>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <INetworkService>().Use <DemoNetworkService>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <CustomizationService>().Use <CustomizationService>()))
                                   .RegisterAction((c, _) => c.Register(Component.For <Stylesheet>().Use <Stylesheet>(@"MapCss/default/default.mapcss")));

                // this is the way to insert custom extensions from outside. You may need to do it for
                // some scenes.
                initAction(_compositionRoot);

                // setup object graph
                _compositionRoot.Setup();

                IsInitialized = true;
            }
            catch (Exception ex)
            {
                _trace.Error(FatalCategoryName, ex, "Cannot setup object graph.");
                throw;
            }
        }