Kephas.Abstractions 11.1.0

Prefix Reserved
dotnet add package Kephas.Abstractions --version 11.1.0                
NuGet\Install-Package Kephas.Abstractions -Version 11.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kephas.Abstractions" Version="11.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kephas.Abstractions --version 11.1.0                
#r "nuget: Kephas.Abstractions, 11.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Kephas.Abstractions as a Cake Addin
#addin nuget:?package=Kephas.Abstractions&version=11.1.0

// Install Kephas.Abstractions as a Cake Tool
#tool nuget:?package=Kephas.Abstractions&version=11.1.0                

Abstractions

Introduction

This package is the foundation for all the other Kephas packages. It consists of multiple areas, which are described below.

Check the following packages for more information:

Logging

The logging abstractions provide implementation agnostic logging contracts. The loggers are available through Injection.

Packages providing specific logging implementations:

The ILogManager singleton service

The log manager is a service registered in the ambient services. It provides the following method:

  • GetLogger(loggerName): ILogger: retrieves the logger with the provided name.
  • GetLogger<T>(): ILogger (extension): retrieves the logger having the same name with the generic type's argument full name.

By default, a NullLoggerManager will be used, if not overwritten with a more specific implementation (NLog, Serilog, Log4Net, or other).

The logger

A logger implements the ILogger contract, is identified by its name and is created by the log manager. For injection purposes, a generic ILogger<TService> service contract is provided to be imported by injectable services.

It provides a single method which logs the provided arguments at the indicated level:

  • Log(level: LogLevel, exception?: Exception, messageFormat: string, params args: object[]).

Note to implementors: the exception may be null, so be cautious and handle this case too. For example, the LoggerExtensions.Log extension method passes a null exception.

For convenience, however, extension methods are provided to log fatal errors, errors, warnings, information, debug and trace data.

Consuming logging services

There are two kinds of components which can consume logging services:

  • Injectable services.
  • Non-injectable services and static classes.

To log anything, each consumer must firstly receive the logger it requires to consume its services by using specific means. Recommendations:

  • Do not use directly specific loggers, like log4net or NLog, instead prefer the ILogger interface. Reason: someday the circumstances may dictate to change the logging framework, and it will be a lot easier to change only the logger implementation compared to all logger specific code.
Injectable services

Injectable services should just import the logger through the constructor, with the type ILogger<ServiceType>, where ServiceType is the type of the service. Alternatively, the service can extend Loggable by providing it, optionally, an ILogManager.

  • Example
    [SingletonAppServiceContract]
    public interface IModelContainer
    {
        //...
    }

    public class ModelContainer : IModelContainer
    {
        public ModelContainer(ILogger<ModelContainer> logger)
        {
            this.Logger = logger;        
        }

        protected ILogger<ModelContainer> Logger { get; }
    }

    // - or - inherit from Loggable, if there are no base class restrictions

    public class ModelContainer : Loggable, IModelContainer
    {
        public ModelContainer(ILogManager? logManager = null)
            : base(logManager)
        {
        }
    }
Non-injectable services and static classes

These classes should use the globally defined ILogManager through LoggingHelper.DefaultLogManager.

  • Examples
    public static class ReflectionHelper
    {
        /// <summary>
        /// Logger instance.
        /// </summary>
        private static readonly ILogger Logger = LoggingHelper.DefaultLogManager.GetLogger<ReflectionHelper>();
	
        //...
    }

Caution: Make sure that at the time of calling DefaultLogManager it is properly initialized with the desired log manager, otherwise a logger logging nothing will be provided.

Dynamic objects

Sometimes it is very useful for objects to provide dynamic behavior, so that, on the fly, new properties may be added to them without recompilation, just like in the dynamic languages like JavaScript or Python. Their properties ca be accessed:

  • directly, with the API defined by their class.
  • by the means of the dynamic keyword.
  • by their name, just like a dictionary.

The IDynamic interface

Objects supporting settings or getting values by the mean of a string key implement the IDynamic interface.

It provides one single indexer:

  • this[key: string]: object. By this mean, the object may be used like a dictionary.

Expando

A ready-to-use expando class is Expando. Upon initialization, a flag controls how the internal dictionary is used: thread safe or not. Depending on it, the inner dictionary is set to a ConcurrentDictionary or Dictionary.

Examples
  • Plain expando
    dynamic expando = new Expando();

    expando.Property = "value";
    Assert.AreEqual("value", expando.Property);
  • Expando over a dictionary
    var dictionary = new Dictionary<string, object>();
    dynamic expando = new Expando(dictionary);

    expando.Property = "value";
    Assert.AreEqual("value", dictionary["Property"]);
  • Access over API, dynamic, or indexer
    public class Person : Expando
    {
        public int Age { get; set; }
    }

    //...
    
    var person = new Person();
    person.Age = 30;     // the age is set through the class API

    dynamic dynPerson = person;
    dynPerson.Age = 23;  // the age is set through the dynamic features
    Assert.AreEqual(23, person.Age);

    person["Age"] = 40;
    Assert.AreEqual(40, person.Age);

    dynPerson.IsOld = true;
    Assert.IsTrue(person["IsOld"]);
  • Expose non-dynamic objects as dynamic
    public class Contact
    {
        public string Name { get; set; }
    }

    //...
    
    var contact = new Contact();
    dynamic dynContact = new Expando(contact);

    dynContact.Name = "John";
    Assert.AreEqual("John", contact.Name);

Usage

Expandos can be successfully used where a dynamic context is useful. Examples:

  • Context objects, used to provide information about the current execution context, passed along the execution flow.
  • Metadata objects, used to provide meta information about entities and other artifacts.
  • Configuration settings.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (30)

Showing the top 5 NuGet packages that depend on Kephas.Abstractions:

Package Downloads
Kephas.Core

Aggregates the most used Kephas infrastructure to provide a . Typically used areas and classes/interfaces/services: - AmbientServices - Data: IIdGenerator, DefaultIdGenerator. Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.

Kephas.Data

Provides abstractions for managing data: retrieval, persistence, query. Typically used areas and classes/interfaces/services: - IDataSpace, IDataContext. - Capabilities: IEntityEntry, EntityEntry. - Conversion: IDataConversionService, IDataConverter, DataConverterBase. - DataSources: IDataSourceService, IDataSourceProvider. - Behaviors: IDataBehavior, DataBehaviorBase, QueryBehaviorBase. - Analysis: IRefPropertiesProvider. - Setup: IDataSetupManager, IDataInstaller. - Validation: IOnValidateBehavior. Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.

Kephas.Messaging

Provides services for messaging, a.k.a. request/response service layer. Typically used areas and classes/interfaces/services: - IMessageProcessor, IMessage, MessageHandlerBase. - Distributed: IMessageBroker, IBrokeredMessage, MessageRouterBase. - Behaviors: IMessagingBehavior, MessagingBehaviorBase. - Events: IEvent. Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.

Kephas.Model

Provides an abstract multi-dimensional modeling infrastructure, containing extensible model elements like dimensions, classifiers, and value types. Typically used areas and classes/interfaces/services: - IModelSpace, IClassifier, IAnnotation, IProperty, IMethod, IParameter. - AttributedModel: AbstractAttribute, AspectAttribute, AspectForAttribute, MixinAttribute, ValueTypeAttribute. Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.

Kephas.Logging.NLog

Provides the NLog logging services implementation. Typically used areas and classes/interfaces/services: - IAmbientServices.WithNLogManager(). Kephas Framework ("stone" in aramaic) aims to deliver a solid infrastructure for applications and application ecosystems.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
11.1.0 27,949 4/13/2022
11.1.0-dev.4 169 4/6/2022
11.1.0-dev.3 147 3/30/2022
11.1.0-dev.2 160 3/23/2022
11.1.0-dev.1 149 3/23/2022
11.0.0 26,065 3/11/2022
11.0.0-dev.7 177 3/7/2022
11.0.0-dev.6 157 2/28/2022
11.0.0-dev.5 154 2/26/2022
11.0.0-dev.4 151 2/24/2022
11.0.0-dev.3 156 2/23/2022
11.0.0-dev.2 155 2/18/2022
11.0.0-dev.1 155 2/7/2022
10.3.0 26,523 1/18/2022
10.2.0 13,938 12/3/2021
10.1.0 20,016 11/23/2021
10.1.0-dev.7 214 11/17/2021
10.1.0-dev.6 189 11/16/2021
10.1.0-dev.5 184 11/10/2021
10.1.0-dev.4 204 11/8/2021
10.1.0-dev.3 170 11/8/2021
10.1.0-dev.2 180 11/4/2021

Please check https://github.com/kephas-software/kephas/releases for the change log.
           Also check the documentation and the samples from https://github.com/kephas-software/kephas/wiki and https://github.com/kephas-software/kephas/tree/master/Samples.