예제 #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            TaskHelper.RunOnUiThread(() => { }).FireAndForget(); // Initialize the synchronization context.

            try {
                IEnumerable <IAutoMapperConfiguration> configurations = container.GetAll <IAutoMapperConfiguration>();

                MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg => configurations.ForEach(configuration => configuration.RegisterMappings(cfg)));

                try {
                    mapperConfiguration.AssertConfigurationIsValid();
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message, "Mapping Validation Error");
                }

                container.RegisterInstance(mapperConfiguration.CreateMapper());

                container.InitializeControllers();
            }
            catch (Exception ex) {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                MessageBox.Show(ex.Message, "MEF Error");
            }

            base.OnStartup(e);
        }
예제 #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            try {
                IEnumerable <IAutoMapperConfiguration> configurations = container.GetAll <IAutoMapperConfiguration>();

                MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg => configurations.ForEach(configuration => configuration.RegisterMappings(cfg)));

                try {
                    mapperConfiguration.AssertConfigurationIsValid();
                }
                catch (Exception ex) {
                    MessageBox.Show($"{ex.Message}\n\n{ex.GetType().FullName}", "Mapping Validation Error");
                }

                container.RegisterInstance(mapperConfiguration.CreateMapper());

                IEnumerable <IController> controllers = container.GetAll <IController>();

                IOrderedEnumerable <IGrouping <int, IController> > groups = controllers.GroupBy(c => c.InitializePriority).OrderBy(g => g.Key);

                foreach (IGrouping <int, IController> group in groups)
                {
                    Task.Run(() => group.ForEachAsync(controller => controller.InitializeAsync())).Wait();
                }
            }
            catch (Exception ex) {
                MessageBox.Show($"{ex.Message}\n\n{ex.GetType().FullName}", "MEF Composition Error");
            }
        }
예제 #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            try {
                IEnumerable <IAutoMapperConfiguration> configurations = container.GetAll <IAutoMapperConfiguration>();

                MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg => configurations.ForEach(configuration => configuration.RegisterMappings(cfg)));

                mapperConfiguration.AssertConfigurationIsValid();

                container.RegisterInstance(mapperConfiguration.CreateMapper());

                container.GetAll <IController>();
            }
            catch (Exception ex) {
                MessageBox.Show($"{ex.Message}\n\n{ex.GetType().FullName}", "MEF or Mapping Error");
            }
        }