protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); #if !(DEBUG) DispatcherUnhandledException += AppDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException; #endif InitializeCultures(); catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(WafConfiguration).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly)); catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly)); container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); // Initialize all presentation services var presentationServices = container.GetExportedValues<IPresentationService>(); foreach (var presentationService in presentationServices) { presentationService.Initialize(); } // Initialize and run all module controllers moduleControllers = container.GetExportedValues<IModuleController>(); foreach (var moduleController in moduleControllers) { moduleController.Initialize(); } foreach (var moduleController in moduleControllers) { moduleController.Run(); } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); #if (DEBUG != true) // Don't handle the exceptions in Debug mode because otherwise the Debugger wouldn't // jump into the code when an exception occurs. DispatcherUnhandledException += AppDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException; #endif catalog = new AggregateCatalog(); // Add the WpfApplicationFramework assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly)); // Load module assemblies as well. See App.config file. foreach (string moduleAssembly in Settings.Default.ModuleAssemblies) { catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly)); } container = new CompositionContainer(catalog); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); // Initialize all presentation services var presentationServices = container.GetExportedValues<IPresentationService>(); foreach (var presentationService in presentationServices) { presentationService.Initialize(); } // Initialize and run all module controllers moduleControllers = container.GetExportedValues<IModuleController>(); foreach (var moduleController in moduleControllers) { moduleController.Initialize(); } foreach (var moduleController in moduleControllers) { moduleController.Run(); } }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); DispatcherUnhandledException += AppDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException; catalog = new AggregateCatalog(); // Add the WpfApplicationFramework assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(IMessageService).Assembly)); // Load module assemblies as well. See App.config file. foreach (string moduleAssembly in Settings.Default.ModuleAssemblies) { catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly)); } container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); // Initialize all presentation services var presentationServices = container.GetExportedValues<IPresentationService>(); foreach (var presentationService in presentationServices) { presentationService.Initialize(); } // Initialize and run all module controllers moduleControllers = container.GetExportedValues<IModuleController>(); foreach (var moduleController in moduleControllers) { moduleController.Initialize(); } foreach (var moduleController in moduleControllers) { moduleController.Run(); } }
public void Run() { PermissionPrincipal permissionsPrincipal = new PermissionPrincipal(); AppDomain.CurrentDomain.SetThreadPrincipal(permissionsPrincipal); if (Assembly.GetCallingAssembly().GetName().Name != ServiceAssemblyName) { throw new Exception(Core.UI.Properties.Resources.ErrorMustBeLoadedFromService); } var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\..\TixCRM.TestModule\bin\Debug")); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetAssembly(typeof(MainWindow)))); catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\..\TixCRM.Core.Services\bin\Debug")); catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\..\TixCRM.Core.Data\bin\Debug")); var container = new CompositionContainer(catalog); container.ComposeParts(this); foreach (var module in modules) { if (CheckModule(module)) { module.Init(menuServiceFactory.CreateMenuService(), container.GetExportedValues<ITixViewModel>().Single(x => x.TixViewModelName == module.ViewModelName), container.GetExportedValues<ITixView>().Single(x => x.TixViewName == module.ViewName), mRegistery); } else { throw new ModuleLoadException(String.Format(Core.UI.Properties.Resources.ErrorCouldNotLoadModule, module.DisplayName)); } } App.Start(container.GetExportedValue<ITixViewModel>("TixCRM.Core.UI.MainViewModel")); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); DispatcherUnhandledException += AppDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException; catalog = new AggregateCatalog(); // Add the WpfApplicationFramework assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(ViewModel).Assembly)); // Add the Waf.BookLibrary.Library.Presentation assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); // Add the Waf.BookLibrary.Library.Applications assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly)); // Load module assemblies as well (e.g. Reporting extension). See App.config file. foreach(string moduleAssembly in Settings.Default.ModuleAssemblies) { catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly)); } container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); moduleControllers = container.GetExportedValues<IModuleController>(); foreach (IModuleController moduleController in moduleControllers) { moduleController.Initialize(); } foreach (IModuleController moduleController in moduleControllers) { moduleController.Run(); } }
static SarifTraceListener() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly())); CompositionContainer container = new CompositionContainer(catalog); SarifTraceListener.Rules = container.GetExportedValues<IRuleDescriptor>(); }
public void DiscoverServices(IServicePool pool) { var registration = new RegistrationBuilder(); registration.ForTypesDerivedFrom<IService>().SelectConstructor((ConstructorInfo[] cInfo) => { if (cInfo.Length == 0) return null; return cInfo[0]; }).Export<IService>(); var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var catalog = new DirectoryCatalog(path, registration); var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection); var services = container.GetExportedValues<IService>(); foreach (var service in services) { service.ServicePool = pool; var interfaces = service.GetType().GetInterfaces(); Type interfaceType = null; foreach (var i in interfaces) { var name = i.FullName; if (!name.Contains("Contracts.IService") && !name.Contains("System.")) { interfaceType = i; break; } } pool.AddService(interfaceType, service); } }
internal static void Initialize(Kernel knl, LogicMgr logicMgr) { lock (syncRoot) { var itasks = container.GetExportedValues <IServise>(); foreach (var servise in itasks) { var lgc = (CoreLogic)servise; lgc.Ctor(knl); logicMgr.Add(lgc); LogHelper.Info(lgc.Name + " loading..."); Csl.Wl(lgc.Name + " loading..."); } knl.Ctor(logicMgr); var batch = new CompositionBatch(); foreach (var logic in knl.GetLgcs()) { batch.AddPart(logic); } try { container.Compose(batch); } catch (CompositionException compositionException) { Debug.WriteLine(compositionException.ToString()); throw; } } }
private static IList<ISpellCast> GetSpells() { // Use MEF to locate the content providers in this assembly var catalog = new AssemblyCatalog(typeof(SpellManager).Assembly); var compositionContainer = new CompositionContainer(catalog); return compositionContainer.GetExportedValues<ISpellCast>().ToList(); }
/// <summary> /// Static Initialization for loading the plugins into the ApplicationPlugins Collection /// </summary> static Plugins() { var catalog = new AggregateCatalog(); //Adds the program's assembly catalog.Catalogs.Add(new AssemblyCatalog(typeof(Plugins).Assembly)); string programassembly = System.Reflection.Assembly.GetAssembly(typeof(Plugins)).Location; string programpath = Path.GetDirectoryName(programassembly); //add the program's path catalog.Catalogs.Add(new DirectoryCatalog(programpath)); _container = new CompositionContainer(catalog); try { ApplicationPlugins = _container.GetExportedValues<IWPFApplicationPlugin>(); } catch (CompositionException compositionException) { throw compositionException; } }
private static IList<IUploadHandler> GetUploadHandlers(IApplicationSettings settings) { // Use MEF to locate the content providers in this assembly var compositionContainer = new CompositionContainer(new AssemblyCatalog(typeof(UploadProcessor).Assembly)); compositionContainer.ComposeExportedValue<IApplicationSettings>(settings); return compositionContainer.GetExportedValues<IUploadHandler>().ToList(); }
static FileSaveServiceFactory() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(IFileSaveService).Assembly)); CompositionContainer container = new CompositionContainer(catalog); services = container.GetExportedValues<IFileSaveService>(); }
private static IList<IContentProvider> GetContentProviders(IKernel kernel) { // Use MEF to locate the content providers in this assembly var compositionContainer = new CompositionContainer(new AssemblyCatalog(typeof(ResourceProcessor).Assembly)); compositionContainer.ComposeExportedValue(kernel); return compositionContainer.GetExportedValues<IContentProvider>().ToList(); }
public void WhenInitializingAModuleWithACatalogPendingToBeLoaded_ThenLoadsTheCatalogInitializesTheModule() { var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(typeof(MefModuleInitializer).Assembly)); var compositionContainer = new CompositionContainer(aggregateCatalog); compositionContainer.ComposeExportedValue(aggregateCatalog); var serviceLocatorMock = new Mock<IServiceLocator>(); var loggerFacadeMock = new Mock<ILoggerFacade>(); var serviceLocator = serviceLocatorMock.Object; var loggerFacade = loggerFacadeMock.Object; compositionContainer.ComposeExportedValue(serviceLocator); compositionContainer.ComposeExportedValue(loggerFacade); var moduleInitializer = compositionContainer.GetExportedValue<IModuleInitializer>(); var repository = compositionContainer.GetExportedValue<DownloadedPartCatalogCollection>(); var moduleInfo = new ModuleInfo("TestModuleForInitializer", typeof(TestModuleForInitializer).AssemblyQualifiedName); repository.Add(moduleInfo, new TypeCatalog(typeof(TestModuleForInitializer))); moduleInitializer.Initialize(moduleInfo); ComposablePartCatalog existingCatalog; Assert.IsFalse(repository.TryGet(moduleInfo, out existingCatalog)); var module = compositionContainer.GetExportedValues<IModule>().OfType<TestModuleForInitializer>().First(); Assert.IsTrue(module.Initialized); }
public void Initialize() { var catalog = new AggregateCatalog(); //Adds the program's assembly catalog.Catalogs.Add(new AssemblyCatalog(typeof(PluginInfrastructre).Assembly)); string programassembly = System.Reflection.Assembly.GetAssembly(typeof(PluginInfrastructre)).Location; string programpath = Path.GetDirectoryName(programassembly); //add the program's path catalog.Catalogs.Add(new DirectoryCatalog(programpath)); _container = new CompositionContainer(catalog); try { //Initialize types found and assign new instances to Plugins Plugins = _container.GetExportedValues<IPlugin>(); } catch (CompositionException compositionException) { throw; } }
internal static void Initialize(CompositionContainer composition) { List<Language> languages = new List<Language>(); if (composition != null) languages.AddRange(composition.GetExportedValues<Language>()); else { languages.Add(new CSharpLanguage()); languages.Add(new VB.VBLanguage()); } // Fix order: C#, VB, IL var langs2 = new List<Language>(); var lang = languages.FirstOrDefault(a => a is CSharpLanguage); if (lang != null) { languages.Remove(lang); langs2.Add(lang); } lang = languages.FirstOrDefault(a => a is VB.VBLanguage); if (lang != null) { languages.Remove(lang); langs2.Add(lang); } langs2.Add(new ILLanguage(true)); for (int i = 0; i < langs2.Count; i++) languages.Insert(i, langs2[i]); #if DEBUG languages.AddRange(ILAstLanguage.GetDebugLanguages()); languages.AddRange(CSharpLanguage.GetDebugLanguages()); #endif allLanguages = languages.AsReadOnly(); }
public void WhenInitializingAModuleWithNoCatalogPendingToBeLoaded_ThenInitializesTheModule() { var aggregateCatalog = new AggregateCatalog(new AssemblyCatalog(typeof(MefModuleInitializer).Assembly)); var compositionContainer = new CompositionContainer(aggregateCatalog); compositionContainer.ComposeExportedValue(aggregateCatalog); var serviceLocatorMock = new Mock<IServiceLocator>(); var loggerFacadeMock = new Mock<ILoggerFacade>(); var serviceLocator = serviceLocatorMock.Object; var loggerFacade = loggerFacadeMock.Object; compositionContainer.ComposeExportedValue(serviceLocator); compositionContainer.ComposeExportedValue(loggerFacade); aggregateCatalog.Catalogs.Add(new TypeCatalog(typeof(TestModuleForInitializer))); var moduleInitializer = compositionContainer.GetExportedValue<IModuleInitializer>(); var moduleInfo = new ModuleInfo("TestModuleForInitializer", typeof(TestModuleForInitializer).AssemblyQualifiedName); var module = compositionContainer.GetExportedValues<IModule>().OfType<TestModuleForInitializer>().First(); Assert.IsFalse(module.Initialized); moduleInitializer.Initialize(moduleInfo); Assert.IsTrue(module.Initialized); }
public void GetValuesByType() { var cat = CatalogFactory.CreateDefaultAttributed(); var container = new CompositionContainer(cat); string itestName = AttributedModelServices.GetContractName(typeof(ITest)); var e1 = container.GetExportedValues<ITest>(); var e2 = container.GetExports<ITest, object>(itestName); Assert.IsInstanceOfType(e1.First(), typeof(T1), "First should be T1"); Assert.IsInstanceOfType(e1.Skip(1).First(), typeof(T2), "Second should be T2"); Assert.IsInstanceOfType(e2.First().Value, typeof(T1), "First should be T1"); Assert.IsInstanceOfType(e2.Skip(1).First().Value, typeof(T2), "Second should be T2"); CompositionContainer childContainer = new CompositionContainer(container); CompositionBatch batch = new CompositionBatch(); batch.AddPart(new T1()); container.Compose(batch); var t1 = childContainer.GetExportedValue<ITest>(); var t2 = childContainer.GetExport<ITest, object>(itestName); Assert.IsInstanceOfType(t1, typeof(T1), "First (resolved) should be T1"); Assert.IsInstanceOfType(t2.Value, typeof(T1), "First (resolved) should be T1"); }
private static IEnumerable<IPlugin> GetPlugins() { var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "."; var catalog = new DirectoryCatalog(path, PluginSearchPattern); var container = new CompositionContainer(catalog); return container.GetExportedValues<IPlugin>(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); #if (DEBUG != true) // Don't handle the exceptions in Debug mode because otherwise the Debugger wouldn't // jump into the code when an exception occurs. DispatcherUnhandledException += AppDispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException; #endif catalog = new AggregateCatalog(); // Add the WpfApplicationFramework assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(Controller).Assembly)); // Add the Waf.BookLibrary.Library.Presentation assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())); // Add the Waf.BookLibrary.Library.Applications assembly to the catalog catalog.Catalogs.Add(new AssemblyCatalog(typeof(ShellViewModel).Assembly)); // Load module assemblies as well (e.g. Reporting extension). See App.config file. foreach(string moduleAssembly in Settings.Default.ModuleAssemblies) { catalog.Catalogs.Add(new AssemblyCatalog(moduleAssembly)); } container = new CompositionContainer(catalog); CompositionBatch batch = new CompositionBatch(); batch.AddExportedValue(container); container.Compose(batch); moduleControllers = container.GetExportedValues<IModuleController>(); foreach (IModuleController moduleController in moduleControllers) { moduleController.Initialize(); } foreach (IModuleController moduleController in moduleControllers) { moduleController.Run(); } }
private static TinyIoCContainer GetIoCContainer() { var container = new TinyIoCContainer(); //Configuration Values var redisToGoUrl = ConfigurationManager.AppSettings["REDISTOGO_URL"]; var botName = ConfigurationManager.AppSettings["BotName"]; //Using MEF to build-up instances var commandProcessorCompositionContainer = new CompositionContainer(new AssemblyCatalog(typeof(ICommandProcessor).Assembly)); var commandProcessors = commandProcessorCompositionContainer.GetExportedValues<ICommandProcessor>(); var contentProviderCompositionContainer = new CompositionContainer(new AssemblyCatalog(typeof(IContentProvider).Assembly)); var contentProviders = contentProviderCompositionContainer.GetExportedValues<IContentProvider>(); //Bootstrapper Tasks container.Register<IBootstrapperPerInstanceTask, RegisterErrorHandling>("RegisterErrorHandling"); container.Register<IBootstrapperPerApplicationTask, Bundles>("Bundles"); container.Register<IBootstrapperPerApplicationTask, RegisterRoutes>("RegisterRoutes"); container.Register<Func<ChatHub>>((c, p) => () => c.Resolve<ChatHub>()); container.Register<IBootstrapperPerApplicationTask, RegisterSignalRDependencies>("RegisterSignalRDependencies"); //Domain container.Register<string>((c, p) => botName); container.Register<IEnumerable<ICommandProcessor>>(commandProcessors); //Singleton container.Register<IEnumerable<IContentProvider>>(contentProviders); //Singleton container.Register<IMessageStore>((c, p) => new RedisMessageStore(0, redisToGoUrl)); //Multi-instance container.Register<IUserStore>((c, p) => new RedisUserStore(0, redisToGoUrl)); //Multi-instance container.Register<ChatHub>(); //Multi-instance return container; }
static CacheFactory() { AggregateCatalog catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(typeof(ICache).Assembly)); CompositionContainer container = new CompositionContainer(catalog); caches = container.GetExportedValues<ICache>(); }
static void Main(string[] args) { var assembly = Assembly.GetExecutingAssembly(); var catalog = new AggregateCatalog( new AssemblyCatalog(assembly), new DirectoryCatalog(Path.GetDirectoryName(assembly.Location)) ); var container = new CompositionContainer(catalog); var workers = container.GetExportedValues<IWorker>().ToArray(); if (workers.Length == 0) return; var flag = new ManualResetEvent(false); Console.CancelKeyPress += (sender, e) => flag.Set(); foreach (var worker in workers) worker.Start(); flag.WaitOne(); foreach (var worker in workers) worker.Stop(); }
public object Index() { var allControllerTypes = from type in GetType().Assembly.GetTypes() where type.BaseType.FullName.Contains("ApiController") select type; var allPublicMethods = allControllerTypes.SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.Instance)) .Where(x => x.CustomAttributes.Any(attr => attr.AttributeType == typeof(HttpGetAttribute))) .Where(x => x.DeclaringType != null && x.DeclaringType.Name.Contains(x.Name) == false) .Where(x => x.DeclaringType != null && !x.DeclaringType.Name.Contains("DemoStudio")) .Where(x => x.DeclaringType != null && !(x.DeclaringType.Name.Contains("Menu") && !x.Name.Contains("CreateIndexes") && !x.Name.Contains("CreateLastFmDataset"))) .Select(x => string.Format("{0}/{1}", x.DeclaringType.Name, x.Name)); // in VS2015 : $"{x.DeclaringType.Name}/{x.Name}" var result = allPublicMethods.ToList(); result.Sort( delegate(string s1, string s2) { if (s1.Contains("Basic") && s2.Contains("Advanced")) return -1; if (s2.Contains("Basic") && s1.Contains("Advanced")) return 1; return string.Compare(s1, s2, StringComparison.Ordinal); } ); FormattedMenuIndex.FormatControllerString(result); var container = new CompositionContainer(new AssemblyCatalog(Assembly.GetExecutingAssembly())); var indexesList = container.GetExportedValues<AbstractIndexCreationTask>().ToList(); var multimapList = container.GetExportedValues<AbstractMultiMapIndexCreationTask>().ToList(); var transformersList = container.GetExportedValues<AbstractTransformerCreationTask>().ToList(); var allLists = new List<string>(); allLists.AddRange(indexesList.Select(x => x.IndexName)); allLists.AddRange(multimapList.Select(x => x.IndexName)); allLists.AddRange(transformersList.Select(x => x.TransformerName)); var resObj = new MenuResults() { ListOfControllers = result, ListOfIndexes = allLists }; return (resObj); }
/// <summary> /// 複数インターフェイス取得 /// </summary> /// <param name="container"></param> private static void Test3(CompositionContainer container) { var types = container.GetExportedValues<IManyTest>(); foreach (IManyTest test in types) { test.Execute(); } }
/// <summary> /// Static ctor /// </summary> public static void Initialize(CompositionContainer compositionContainer) { mappedTypeBuilders = new Dictionary<string, IMappedTypeBuilder>(); foreach (var builder in compositionContainer.GetExportedValues<IMappedTypeBuilder>()) { mappedTypeBuilders.Add(builder.ClassName, builder); } }
public List<IParserPlugin> AllPlugins() { var executablePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var catalog = new DirectoryCatalog(Path.Combine(executablePath, "plugins")); var container = new CompositionContainer(catalog); return container.GetExportedValues<IParserPlugin>().ToList(); }
static ModelBasedNavigationHelper() { var catalog = new AssemblyCatalog(typeof(ModelBasedNavigationHelper).Assembly); Container = new CompositionContainer(catalog); ViewModelsSource = Container.GetExportedValues<IHostedControlViewModel>().ToList(); OpenGenericGetExportedValue = ((Func<object>) Container.GetExportedValue<object>).Method.GetGenericMethodDefinition(); }
public AzureCommandFactory(AppType appType) { var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory, "KonfDB*.dll")); var container = new CompositionContainer(catalog); _commands = container.GetExportedValues<ICommand>().Where(x => (x.Type & appType) == appType); Commands = _commands.ToList(); }
static void Main() { var catalog = new DirectoryCatalog("."); var container = new CompositionContainer(catalog); var descriptors = container.GetExportedValues<ReaderDbCommandDescriptor>(); foreach (var descriptor in descriptors) Console.WriteLine(descriptor.ProviderName); }
public ContentCatalog(CompositionContainer container) { var content = container.GetExportedValues<IContent>(); if (content != null) { mInternalList.AddRange(content); } }