public App() { SyncfusionLicenseProvider.RegisterLicense("##SyncfusionLicense##"); var catalog = new ApplicationCatalog(); Container = new CompositionContainer(catalog); }
private void AssembleComponents() { try { //Step 1: Initializes a new instance of the // System.ComponentModel.Composition.Hosting.AssemblyCatalog // class with the current executing assembly. var acatalog = new ApplicationCatalog(); //the following should be removed outside of dev environments. it is only added so the library containing the downloader //and other parts can be found, as they live in a seperate project and the dll is in a different folder string currpath = Environment.CurrentDirectory; currpath = currpath.Replace("DotaMatchAnalyzerClient", "OpenDotaInterface"); var nothercatalog = new DirectoryCatalog(currpath); var catalog = new AggregateCatalog(acatalog, nothercatalog); //Step 2: The assemblies obtained in step 1 are added to the //CompositionContainer var container = new CompositionContainer(catalog); //Step 3: Composable parts are created here i.e. //the Import and Export components // assembles here container.ComposeParts(this); } catch (Exception ex) { throw ex; } }
static int Main(string[] args) { using (var catalogue = new ApplicationCatalog()) using (var container = new CompositionContainer(catalogue)) { return(container.GetExportedValue <Program>().Run(args)); } }
public void Run() { using (var catalogue = new ApplicationCatalog()) using (var container = new CompositionContainer(catalogue)) { container.GetExportedValue <IGenericService <string> >().Print("asdf"); // System.String:asdf container.GetExportedValue <IGenericService <int> >().Print(123); // System.Int32:123 } }
public static void Main(string[] args) { var catalog = new ApplicationCatalog(); var container = new CompositionContainer(catalog); var converter = container.GetExportedValue <Converter>(); var y = "1.5"; var x = converter.Convert <float, string>(y); Console.ReadLine(); }
private void Run() { var catalog = new ApplicationCatalog(); var container = CreateCompositionContainer(catalog); container.ComposeParts(this); foreach (var pair in this.basket.GetAppleDictionary()) { Console.WriteLine("{0}: {1}", pair.Key, pair.Value); } }
/// <summary> /// Initialises a new instance of the <see cref="Classes"/> class. /// </summary> public Classes() { // NOTE: This is a generic application catalogue, for demonstration purposes. // It is likely you'd rather use a Directory or Assembly catalogue // instead, to make the application more scalable, in line with the MEF // ideology. var catalogue = new ApplicationCatalog(); var container = new CompositionContainer(catalogue); container.ComposeParts(this); }
public void Dispose_ShouldNotThrow() { using (var app = new Application()) { app.AppMain(() => { using (var catalog = new ApplicationCatalog()) { } }); } }
public void ToString_WhenCatalogDisposed_ShouldNotThrow() { using (var app = new Application()) { app.AppMain(() => { var catalog = new ApplicationCatalog(); catalog.Dispose(); catalog.ToString(); }); } }
public void ICompositionElementOrigin_WhenCatalogDisposed_ShouldNotThrow() { using (var app = new Application()) { app.AppMain(() => { var catalog = new ApplicationCatalog(); catalog.Dispose(); var origin = ((ICompositionElement)catalog).Origin; }); } }
public void ICompositionElementDisplayName_WhenCatalogDisposed_ShouldNotThrow() { using (var app = new Application()) { app.AppMain(() => { var catalog = new ApplicationCatalog(); catalog.Dispose(); var displayName = ((ICompositionElement)catalog).DisplayName; }); } }
public void Dispose_CanBeCalledMultipleTimes() { using (var app = new Application()) { app.AppMain(() => { var catalog = new ApplicationCatalog(); catalog.Dispose(); catalog.Dispose(); catalog.Dispose(); }); } }
/// <summary> /// Creates a <see cref="CompositionContainer"/> with an <see cref="ApplicationCatalog"/> a /// <see cref="ConfigurationExportProvider"/>. The /// <see cref="ConfigurationExportProvider"/> is reads from the application's config file, /// either an App.Config or Web.Config file. /// </summary> /// <param name="additionalProviders"></param> /// <returns></returns> public static CompositionContainer CreateApplicationAndConfigFileContainer(params ExportProvider[] additionalProviders) { var applicationCatalog = new ApplicationCatalog(); var configExportProvider = new ConfigurationExportProvider(new FileConfigurationSource()); var exportProviders = new ExportProvider[1 + additionalProviders.Length]; exportProviders[0] = configExportProvider; Array.Copy(additionalProviders, 0, exportProviders, 1, additionalProviders.Length); var result = new CompositionContainer(applicationCatalog, configExportProvider); return(result); } // TODO: Test
public void GetExports_NullAsConstraintArgument_ShouldThrowArgumentNull() { ExceptionAssert.ThrowsArgument <ArgumentNullException>("definition", () => { using (var app = new Application()) { app.AppMain(() => { var catalog = new ApplicationCatalog(); catalog.GetExports((ImportDefinition)null); }); } }); }
public void GetEnumerator_WhenCatalogDisposed_ShouldThrowObjectDisposed() { ExceptionAssert.Throws <ObjectDisposedException>(RetryMode.DoNotRetry, () => { using (var app = new Application()) { app.AppMain(() => { var catalog = new ApplicationCatalog(); catalog.Dispose(); var enumerator = catalog.GetEnumerator(); }); } }); }
public static void Main(string[] args) { var catalog = new ApplicationCatalog(); var container = new CompositionContainer(catalog); IDictionary <int, IApple> dict = new Dictionary <int, IApple>(); for (int i = 0; i < 10; i++) { dict.Add(i, container.GetExportedValue <IApple>()); } foreach (var pair in dict) { Console.WriteLine("{0}: {1}", pair.Key, pair.Value); } }
/// <summary> /// Defines the entry point of the application. See AssemblyInfo.cs for example of how to set service name, display name, and description. /// </summary> /// <param name="args">The arguments.</param> /// <returns>System.Int32.</returns> internal static int Main(string[] args) { // Important Note: You should run as Administrator to interact with the service control manager. // Override the passed arguments for testing purposes. Use '-', '--', '/', or '//' as flags. // Uncomment one to test the service control arguments. //args = new[] { "-i" }; // or "install" //args = new[] { "-u" }; // or "uninstall" //args = new[] { "-s" }; // or "start" //args = new[] { "-t" }; // or "stop" using (var catalog = new ApplicationCatalog()) using (var container = new CompositionContainer(catalog)) using (var service = container.GetExport <ExtensibleServiceBase>()?.Value as Service) { if (service == null) { return(1); } Console.Title = "Sample Console"; Console.CursorVisible = false; var argumentsToInject = container.GetExportedValues <IArgument>(); var arguments = global::Arguments.Arguments.NewArguments(args, argumentsToInject); arguments.Process(); if (Environment.UserInteractive) { service.OnStart(args); Console.WriteLine(); Console.WriteLine("This application will run as a console application and a service application."); Console.WriteLine(); Console.WriteLine("Press any key to exit."); Console.ReadKey(); service.OnStop(); } else { Run(service); } } return(0); }
protected override void Configure() { Contract.Ensures(this.container != null); var catalog = new ApplicationCatalog(); this.container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddExportedValue <IBus>(new Bus(new CmAdapter())); batch.AddExportedValue(this.container); batch.AddExportedValue(catalog); this.container.Compose(batch); }
private ComposablePartCatalog GetInterceptionCatalog() { _applicationCatalog = new ApplicationCatalog(); _adapterdirectoryCatalog = new DirectoryCatalog(AdaptersDirectory); _pluginsdirectoryCatalog = new DirectoryCatalog(PluginsDirectory); var catalog = new AggregateCatalog(_applicationCatalog, _adapterdirectoryCatalog, _pluginsdirectoryCatalog); var cfg = new InterceptionConfiguration().AddInterceptionCriteria( new PredicateInterceptionCriteria( new CopyConfigInterceptor(_robot.Settings), def => def.ExportDefinitions.First().ContractName.Contains("IAdapter") || def.ExportDefinitions.First().ContractName.Contains("IRobotPlugin"))); return(new InterceptingCatalog(catalog, cfg)); }
public void GetExports_WhenCatalogDisposed_ShouldThrowObjectDisposed() { ExceptionAssert.Throws <ObjectDisposedException>(RetryMode.DoNotRetry, () => { using (var app = new Application()) { app.AppMain(() => { var catalog = new ApplicationCatalog(); catalog.Dispose(); var definition = ImportDefinitionFactory.Create(); catalog.GetExports(definition); }); } }); }
public ExtensionManager(string pluginFolder) { var directoryCatalog = new DirectoryCatalog(pluginFolder); var domainCatalog = new ApplicationCatalog(); var aggregateCatalog = new AggregateCatalog(directoryCatalog, domainCatalog); _container = new CompositionContainer(aggregateCatalog); try { _container.ComposeParts(this); } catch (CompositionException compositionException) { Console.WriteLine(compositionException.ToString()); } }
public void Test_GetEnumerator() { using (var app = new Application()) { app.AppMain(() => { using (var catalog = new ApplicationCatalog()) { var result = catalog.Count(); //Cross AppDomain AssertFailedException does not marshall if (result < 0) { throw new Exception("Assert.IsTrue(result > 0);"); } } }); } }