Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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;
            }
        }