public MefDependencyResolver(CompositionHost rootCompositionScope) : base(new Export<CompositionContext>(rootCompositionScope, rootCompositionScope.Dispose)) { if (rootCompositionScope == null) { throw new ArgumentNullException("rootCompositionScope"); } var factoryContract = new CompositionContract(typeof(ExportFactory<CompositionContext>), null, new Dictionary<string, object> { { "SharingBoundaryNames", new[] { "HttpRequest" } } }); this.RequestScopeFactory = (ExportFactory<CompositionContext>)rootCompositionScope.GetExport(factoryContract); }
public StandaloneDependencyResolver(CompositionHost rootCompositionScope) : base(new Export<CompositionContext>(rootCompositionScope, rootCompositionScope.Dispose)) { if (rootCompositionScope == null) { throw new ArgumentNullException(nameof(rootCompositionScope)); } var metadataConstraints = new Dictionary<string, object> { { "SharingBoundaryNames", new[] { "HttpRequest" } } }; var factoryContract = new CompositionContract(typeof(ExportFactory<CompositionContext>), contractName: null, metadataConstraints: metadataConstraints); this.requestScopeFactory = (ExportFactory<CompositionContext>)rootCompositionScope.GetExport(factoryContract); }
private OmnisharpWorkspace CreateWorkspace( CompositionHost compositionHost, Dictionary<string, string> sourceFiles) { compositionHost = compositionHost ?? CreatePluginHost(typeof(CodeCheckService).GetTypeInfo().Assembly); var workspace = compositionHost.GetExport<OmnisharpWorkspace>(); AddProjectToWorkspace(workspace, "project.json", new[] { "dnx451", "dnxcore50" }, sourceFiles); // Logic is copied from TestHelper, no idea what's waiting for. Thread.Sleep(50); return workspace; }
public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider, IOmnisharpEnvironment env, ILoggerFactory loggerFactory, ISharedTextWriter writer, IOmnisharpAssemblyLoader loader, IOptions<OmniSharpOptions> optionsAccessor) { Func<RuntimeLibrary, bool> shouldLoad = lib => lib.Dependencies.Any(dep => dep.Name == "OmniSharp.Abstractions" || dep.Name == "OmniSharp.Roslyn"); var assemblies = DependencyContext.Default .RuntimeLibraries .Where(shouldLoad) .SelectMany(lib => lib.Assemblies) .Select(each => loader.Load(each.Name)) .ToList(); PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Value, assemblies); Workspace = PluginHost.GetExport<OmnisharpWorkspace>(); if (env.TransportType == TransportType.Stdio) { loggerFactory.AddStdio(writer, (category, level) => LogFilter(category, level, env)); } else { loggerFactory.AddConsole((category, level) => LogFilter(category, level, env)); } var logger = loggerFactory.CreateLogger<Startup>(); foreach (var assembly in assemblies) { logger.LogDebug($"Loaded {assembly.FullName}"); } app.UseRequestLogging(); app.UseExceptionHandler("/error"); app.UseMiddleware<EndpointMiddleware>(); app.UseMiddleware<StatusMiddleware>(); app.UseMiddleware<StopServerMiddleware>(); if (env.TransportType == TransportType.Stdio) { logger.LogInformation($"Omnisharp server running using {nameof(TransportType.Stdio)} at location '{env.Path}' on host {env.HostPID}."); } else { logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}."); } // ProjectEventForwarder register event to OmnisharpWorkspace during instantiation PluginHost.GetExport<ProjectEventForwarder>(); // Initialize all the project systems foreach (var projectSystem in PluginHost.GetExports<IProjectSystem>()) { try { projectSystem.Initalize(Configuration.GetSection(projectSystem.Key)); } catch (Exception e) { var message = $"The project system '{projectSystem.GetType().Name}' threw exception during initialization.\n{e.Message}\n{e.StackTrace}"; // if a project system throws an unhandled exception it should not crash the entire server logger.LogError(message); } } // Mark the workspace as initialized Workspace.Initialized = true; logger.LogInformation("Configuration finished."); }
public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider, ILibraryManager manager, IOmnisharpEnvironment env, ILoggerFactory loggerFactory, ISharedTextWriter writer, IOptions<OmniSharpOptions> optionsAccessor) { var assemblies = manager.GetReferencingLibraries("OmniSharp.Abstractions") .SelectMany(libraryInformation => libraryInformation.LoadableAssemblies) .Concat( manager.GetReferencingLibraries("OmniSharp.Roslyn") .SelectMany(libraryInformation => libraryInformation.LoadableAssemblies) ) .Select(assemblyName => Assembly.Load(assemblyName)); PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Options, assemblies); Workspace = PluginHost.GetExport<OmnisharpWorkspace>(); Func<string, LogLevel, bool> logFilter = (category, type) => (category.StartsWith("OmniSharp", StringComparison.OrdinalIgnoreCase) || string.Equals(category, typeof(ErrorHandlerMiddleware).FullName, StringComparison.OrdinalIgnoreCase)) && env.TraceType <= type; if (env.TransportType == TransportType.Stdio) { loggerFactory.AddStdio(writer, logFilter); } else { loggerFactory.AddConsole(logFilter); } var logger = loggerFactory.CreateLogger<Startup>(); app.UseRequestLogging(); app.UseErrorHandler("/error"); app.UseMiddleware<EndpointMiddleware>(); app.UseMiddleware<StatusMiddleware>(); app.UseMiddleware<StopServerMiddleware>(); if (env.TransportType == TransportType.Stdio) { logger.LogInformation($"Omnisharp server running using stdio at location '{env.Path}' on host {env.HostPID}."); } else { logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}."); } // Forward workspace events PluginHost.GetExport<ProjectEventForwarder>(); foreach (var projectSystem in PluginHost.GetExports<IProjectSystem>()) { try { projectSystem.Initalize(Configuration.GetSubKey(projectSystem.Key)); } catch (Exception e) { //if a project system throws an unhandled exception //it should not crash the entire server logger.LogError($"The project system '{projectSystem.GetType().Name}' threw an exception.", e); } } // Mark the workspace as initialized Workspace.Initialized = true; logger.LogInformation("Solution has finished loading"); }
public static void SetConfiguration( ContainerConfiguration configuration ) { Contract.Requires( configuration != null ); if ( IsInitialized ) throw new InvalidOperationException( WebExceptionMessage.CompositionProviderAlreadyInitialized ); container = configuration.CreateContainer(); var boundaryNames = new Dictionary<string, object> { { "SharingBoundaryNames", new[] { Boundary.PerRequest } } }; var factoryContract = new CompositionContract( typeof( ExportFactory<CompositionContext> ), null, boundaryNames ); requestScopeFactory = (ExportFactory<CompositionContext>) container.GetExport( factoryContract ); ConfigureMvc(); ConfigureWebApi(); ConfigureComposition(); }
/// <summary> /// Used to override the default conventions for controller/part dependency injection. /// Cannot be used in conjunction with any other methods on this type. Most applications /// should not use this method. /// </summary> /// <param name="configuration">A configuration containing the controller types and other parts that /// should be used by the composition provider.</param> public static void SetConfiguration(ContainerConfiguration configuration) { if (configuration == null) throw new ArgumentNullException("catalog"); if (IsInitialized) throw new InvalidOperationException("Already initialized."); // We add RSF with no conventions (overriding anything set as the default in configuration) _container = configuration.CreateContainer(); var factoryContract = new CompositionContract(typeof(ExportFactory<CompositionContext>), null, new Dictionary<string, object> { { "SharingBoundaryNames", new[] { Boundaries.HttpRequest, Boundaries.DataConsistency, Boundaries.UserIdentity }} }); _requestScopeFactory = (ExportFactory<CompositionContext>)_container.GetExport(factoryContract); ConfigureMvc(); ConfigureWebApi(); }