Kuchulem.DotNet.EntityAttributeValue.Abstractions 1.0.0-alpha.27

This is a prerelease version of Kuchulem.DotNet.EntityAttributeValue.Abstractions.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Kuchulem.DotNet.EntityAttributeValue.Abstractions --version 1.0.0-alpha.27                
NuGet\Install-Package Kuchulem.DotNet.EntityAttributeValue.Abstractions -Version 1.0.0-alpha.27                
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="Kuchulem.DotNet.EntityAttributeValue.Abstractions" Version="1.0.0-alpha.27" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kuchulem.DotNet.EntityAttributeValue.Abstractions --version 1.0.0-alpha.27                
#r "nuget: Kuchulem.DotNet.EntityAttributeValue.Abstractions, 1.0.0-alpha.27"                
#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 Kuchulem.DotNet.EntityAttributeValue.Abstractions as a Cake Addin
#addin nuget:?package=Kuchulem.DotNet.EntityAttributeValue.Abstractions&version=1.0.0-alpha.27&prerelease

// Install Kuchulem.DotNet.EntityAttributeValue.Abstractions as a Cake Tool
#tool nuget:?package=Kuchulem.DotNet.EntityAttributeValue.Abstractions&version=1.0.0-alpha.27&prerelease                

DotNet.EntityAttributeValue.Abstractions

NuGet Version NuGet Preversion

This library provides abstractions for the Entity-Attribute-Value model.

(From Wikipedia) An entity–attribute–value model (EAV) is a data model optimized for the space-efficient storage of sparse—or ad-hoc—property or data values, intended for situations where runtime usage patterns are arbitrary, subject to user variation, or otherwise unforeseeable using a fixed design. The use-case targets applications which offer a large or rich system of defined property types, which are in turn appropriate to a wide set of entities, but where typically only a small, specific selection of these are instantiated (or persisted) for a given entity. Therefore, this type of data model relates to the mathematical notion of a sparse matrix.

EAV is also known as object–attribute–value model, vertical database model, and open schema.

About abstraction

Abstraction is a core concept of Object Oriented Programing (OOP). It alows to hide complexity from the end-user (here a developer) using, among other concepts, interfaces and abstract classes.

A real-life example of abstraction is the tap you use to pour water in a glass.

You simply need to bring a glass, turn on the tap to run water and turn it of when the glass is full.

How water is processed to be cleaned, delivered to the tap or eventually discharged from the sink is not important for your task.

The tap installed in the kitchen is an implementation of a tap interface that uses the water delivery system. All you have to know is that when you turn it on, water is pouring and when you turn it off, it stops.

If you change the tap in the kitchen, you change the implementation but the way you use it is still the same : when you turn it on water is pouring and when you turn it off it stops. The interface is unchanged, the complexity is still hidden.

The same goes for OOP, with abstraction we bring interfaces and abstract classes to provide a consistent way of implementing some mechanics. If you change the implementation you do not need to change anything else.

How to install

Choose the method that suits your needs.

Package Manager

Install-Package Kuchulem.DotNet.EntityAttributeValue.Abstractions -Version 1.0.0

.net CLI

dotnet add package Kuschulem.DotNet.EntityAttributeValue.Abstractions --version 1.0.0

package reference

<PackageReference Include="Kuschulem.EntityAttributeValue.Abstractions" Version="1.0.0" />

Usage

As this library provide abstraction, you won't use it alone. Either you will use it with another library implementing it or you will write your own code implementing the library.

In either way, when manipulating the implementations you will prefere to use the interfaces or abstract classes from the abstraction library than the implemented classes. So when changing implementation you won't have anything to change.

Example implementing and using IEavValueConverterProvider :

The IEavValueConverterProvider is an abstraction for a service that will provide services to convert a raw value (as stored in db) to a typed and usable value in the application.

// Implementing the IEavValueConverterProvider
namespace MyApp.EavImplementations
{
    /// <summary>
    /// Implements the IEavValueConverterProvider interface
    /// </summary>
    public class EavValueConverterProvider : IEavValueConverterProvider
    {
        public IEavValueConverterProvider Register<T>(
            EavValueKind valueKind, 
            IEavValueConverter<T> converter
        ) {
            // implentation of the method
        }

        public IEavValueConverterProvider Register<T>(
            IEavAttribute attribute, 
            IEavValueConverter<T> converter
        ) {
            // implentation of the method
        }

        public IEavValueConverter<T> GetConverter<T>(EavValueKind valueKind)
        {
            // implentation of the method
        }

        public IEavValueConverter<T> GetConverter<T>(IEavAttribute attribute)
        {
            // implentation of the method
        }

        public bool TryGetConverter<T>(
            EavValueKind valueKind, 
            out IEavValueConverter<T>? converter
        ) {
            // implentation of the method
        }

        public bool TryGetConverter<T>(IEavAttribute attribute, out IEavValueConverter<T>? converter)
        {
            // implentation of the method
        }
    }
}

// Define a service that uses the provider
namespace MyApp.Services
{
    public class SampleService
    {
        private readonly IEavValueConverterProvider converterProvider;

        /// <summary>
        /// Expects an instance of IEavValueConverterProvider to be 
        /// </summary>
        public SampleService(IEavValueConverterProvider converterProvider)
        {
            this.converterProvider = converterProvider;
        }

        public DateTime GetBestBeforeDate(FoodProduct product)
        {
            // Code to retrieve the product
            IEavValue bestBeforeValue = product.Values.first(
                v => v.Attribute.attributeName === "bestBeforeDate"
            );

            return (DateTime) converterProvider.GetConverter(bestBeforeValue.Attribute)
                .Convert(bestBeforeValue);
        }
    }
}

In this example (a little dumb), we never use explicitly the EavValueConverterProvider class, instead we use the abstraction with the IEavValueConverterProvider interface. The same goes for the IEavValue interface.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Kuchulem.DotNet.EntityAttributeValue.Abstractions:

Package Downloads
Kuchulem.DotNet.EntityAttributeValue.Converters

Default converters implementation for Kuchulem.DotNet.EntityAttributeValue.Abstractions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-alpha.29 86 10/4/2023
1.0.0-alpha.27 66 10/4/2023
1.0.0-alpha.9 70 10/1/2023
1.0.0-alpha.1 67 10/1/2023