Skip to content

Platform specific: .NET 4.6 onwards

Ioan Crisan edited this page Dec 8, 2016 · 2 revisions

The .NET 4.6 platform specific infrastructure

The .NET 4.6 platform brings a specific implementation to the infrastructure needed for the runtime.

Remarks: this applies also to the compatible Mono framework (from version 4.6 onwards).

The Net46AssemblyLoader class

This class is used to load an assembly, both by name and by path.

  • Service contract: IAssemblyLoader.
  • Instancing: shared.
  • Mode: single.

The Net46AppRuntime class

This class is used to provide the assemblies of the running application. Upon

  • Service contract: IAppRuntime.
  • Instancing: shared.
  • Mode: single.

Net46AmbientServicesBuilderExtensions

This static class provides convenience methods for initializing the foundation-app-runtime with platform specific services. Both Net45AssemblyLoader and Net45Runtime services are registered in the ambient services with their declared service contracts.

Example

    // the runtime is initialized with all the assemblies found in the root application folder filtered by the given condition,
    // in this case all assemblies which have the name starting with "MyApp."
    var ambientServicesBuilder = new AmbientServicesBuilder()
                                       .WithNet45AppRuntime(n => n.Name.StartsWith("Kephas.") || n.Name.StartsWith("MyApp."));
    var myClassLogger = ambientServicesBuilder.AmbientServices.LogManager.GetLogger<MyClass>();

Example for unit testing/code generation

    // the runtime is initialized with all the assemblies found at the location specified by the given setting.
    // in this particular case we need to load the assemblies for the client model found at given location
    // so that the tool can generate the respective TypeScript entities.
    // the ambient services passed in to the builder constructor ensures that not the global ambient services are initialized,
    // but the indicated ones.
    var ambientServicesBuilder = await
        new AmbientServicesBuilder(new AmbientServices())
            .WithDebugLogManager()
            .WithNet45AppRuntime(n => n.Name.StartsWith("Kephas.") || n.Name.StartsWith("MyApp."), GetSetting(App.TypeScriptGeneratedDtoAppLocationSetting))
            .WithMefCompositionContainerAsync().PreserveThreadContext();

Clone this wiki locally