Ejemplo n.º 1
0
        protected override void Load(ContainerBuilder builder)
        {
            var pluginAssemblies = Directory.GetFiles(PLUGIN_DIR, "*.dll", SearchOption.AllDirectories)
                                   .Select(a => Path.GetFullPath(a))
                                   .Select(a => Assembly.LoadFile(a))
                                   .ToArray();

            var allAssemblies = pluginAssemblies
                                .Concat(new[]
            {
                Assembly.GetAssembly(typeof(MainWindow)),
                Assembly.GetAssembly(typeof(NuspecComparer)),
                Assembly.GetAssembly(typeof(CommandManager))
            })
                                .ToArray();

            // register all plugins
            builder.RegisterAssemblyTypes(allAssemblies)
            .Where(t => t.GetInterfaces().Contains(typeof(IPlugin)) && !t.IsAbstract)
            .As <IPlugin>()
            .InstancePerLifetimeScope();

            // register all services
            builder.RegisterAssemblyTypes(allAssemblies)
            .Where(t => t.GetInterfaces().Contains(typeof(IService)) && !t.IsAbstract)
            .AsSelf()
            .AsImplementedInterfaces()
            .InstancePerLifetimeScope();

            // load settings from all assemblies
            foreach (var t in allAssemblies.SelectMany(a => AppModule.GetTypesFromAssembly <ISettings>(a)).Where(a => !a.IsAbstract))
            {
                builder.Register(a =>
                {
                    var manager = a.Resolve <ISettingsManager>();

                    var settings = Activator.CreateInstance(t) as ISettings;

                    return(manager.Load(settings.Id, t));
                })
                .SingleInstance()
                .As(new Type[] { t, typeof(ISettings) });
            }

            // register all additional modules
            builder.RegisterAssemblyModules(pluginAssemblies);

            base.Load(builder);
        }
Ejemplo n.º 2
0
        public App()
        {
            ProfileOptimization.SetProfileRoot(GetProgramdataPath());
            ProfileOptimization.StartProfile("Startup.Profile");

            DispatcherHelper.Initialize();

            string[] args = Environment.GetCommandLineArgs();

            if (args.Contains("cleansettings"))
            {
                Settings.Default.Reset();

                File.Delete(AppModule.GetProgramdataPath("Storage.db"));
            }

            Settings.Default.Upgrade();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
        }