BMEcatSharp.Microsoft.Extensions.DependencyInjection 1.0.5

dotnet add package BMEcatSharp.Microsoft.Extensions.DependencyInjection --version 1.0.5                
NuGet\Install-Package BMEcatSharp.Microsoft.Extensions.DependencyInjection -Version 1.0.5                
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="BMEcatSharp.Microsoft.Extensions.DependencyInjection" Version="1.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BMEcatSharp.Microsoft.Extensions.DependencyInjection --version 1.0.5                
#r "nuget: BMEcatSharp.Microsoft.Extensions.DependencyInjection, 1.0.5"                
#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 BMEcatSharp.Microsoft.Extensions.DependencyInjection as a Cake Addin
#addin nuget:?package=BMEcatSharp.Microsoft.Extensions.DependencyInjection&version=1.0.5

// Install BMEcatSharp.Microsoft.Extensions.DependencyInjection as a Cake Tool
#tool nuget:?package=BMEcatSharp.Microsoft.Extensions.DependencyInjection&version=1.0.5                

OpenTransSharp and BMEcatSharp

openTRANS BMEcat Supports .NET
NuGet Downloads MPL-2.0 License

About This Project

This project enables reading, editing, writing and validating openTRANS® 2.1 and BMEcat® 2005 files. While developing, your IntelliSense is enriched with contents of the official specification-documents. It also provides seamless integration into Microsoft.Extensions.DependencyInjection and ASP.NET Core.

This project is built on the .NET platform and uses the MPL 2.0 license (see MPL 2.0 TLDR; for what that means for you).

Features
  • Compatible with .NET Standard 2.0 or .NET 6+
  • Rich IntelliSense extended with contents of the official specification-documents
    • Meaning of elements/attributes
    • Required elements
    • Choices between elements
  • Reading/editing/writing BMEcat®- and openTRANS®-files
    • Enums where possible, like LanguageCodes, Unit, PackageUnit, CountryCode, OrderType, MimePurpose, PartyRole,... and many more
  • Validation against official XSDs
    • Including adding custom XSD validations (see UDX below)
  • Proper support for User-Defined-Extension data (UDX)
    • Enhance your documents with custom data
  • Microsoft.Extensions.DependencyInjection integration
    • Extension methods for service registration (with optional options)
  • ASP.NET Core integration
    • Model-binding support
    • Model state support
    • Custom encodings and content-types support
  • BMEcat® 2005 support
    • Module Classification Systems, Catalog Groups Systems, and Feature Systems
    • Module Product Configuration
    • Module Price Formulas
    • Module Integrated Procurement Point
    • Multilingual Strings
  • openTRANS® 2.1 support
    • RFQ (request for quotation)
    • Quotation
    • Order
    • Order-Change
    • Order-Response (confirmation of order)
    • Dispatch-Notification
    • Receipt-Acknowledgement (acknowledgement of receipt of goods)
    • Invoice
    • Invoice-List (collective invoice)
    • Remittance-Advice (Notification or remittance)
    • Multilingual Strings

Usage

Reading

Here are 3 ways of reading a openTRANS®-document in ASP.NET Core:

Note: for BMEcat®-documents, it works the same way, but using IBMEcatXmlSerializerFactory instead of IOpenTransXmlSerializerFactory.

...
using OpenTransSharp;
using OpenTransSharp.Validation;
using OpenTransSharp.Xml;
...
[ApiController]
[Route("[controller]")]
public class ValidationController : ControllerBase
{
    private readonly IOpenTransXmlSerializerFactory serializerFactory;

    public ValidationController(IOpenTransXmlSerializerFactory serializerFactory)
    {
        this.serializerFactory = serializerFactory ?? throw new ArgumentNullException(nameof(serializerFactory));
    }

    [HttpPost("via-model-binding")]
    public void ViaModelBinding(Order order)
    {
        // validation implicitly by model binder
    }

    [HttpPost("via-stream")]
    public void ViaStream()
    {
        var serializer = serializerFactory.Create<Order>();

        using var stream = Request.BodyReader.AsStream();
        var document = serializer.Deserialize<Order>(stream);

        document.EnsureValid(serializer);
        // or manually validate your document
        //var validationResult = document.Validate(serializer);
    }

    [HttpPost("via-file")]
    public void ViaFile(IFormFile file)
    {
        var serializer = serializerFactory.Create<Order>();

        var stream = file.OpenReadStream();
        var document = serializer.Deserialize<Order>(stream);

        document.EnsureValid(serializer);
    }
}
Editing and Writing

openTRANS®- and BMEcat®-documents can be easily modelled like any other C# Type.

Rich IntelliSense helps you building the documents in the right, valid way, be leveraging the content of the specifications.

using OpenTransSharp;
using OpenTransSharp.Xml;
...
var serializer = serializerFactory.Create<Order>();

var document = new Order()
{
	Type = OrderType.Express    
}
document.Header = new OrderHeader
{
    ControlInformation = new ControlInformation
    {
        GenerationDate = DateTime.UtcNow,
        GeneratorInfo = "Demo"
    },
    SourcingInformation = new SourcingInformation { ... }
    ...
};
document.Items.Add(new OrderItem
{
    LineItemId = "1",
    ProductId = new ProductId 
    { 
        SupplierPid = new SupplierPid("A0123456789", SupplierPidTypeValues.Ean);    
    },
    Quantity = 2,
    OrderUnit = PackageUnit.C62, // pieces
    ...
});

var serializedString = serializer.Serialize(document);
Validation

You can validate all root-documents like BMEcatDocument, Order, Invoice,... against the official XSDs - without having to fiddle with them. Validation is easy with the provided Validate extensions method.

You can manually validate you documents like this:

using OpenTransSharp;
using OpenTransSharp.Validation;
using OpenTransSharp.Xml;
// if you want to validate BMEcat® documents use the following namespaces:
//using BMEcatSharp;
//using BMEcatSharp.Validation;
//using BMEcatSharp.Xml;
...
var validationResult = order.Validate(serializer);

if (!validationResult.IsValid)
{
    foreach(var error in validationResult.Errors)
    {
    	foreach(var message in error.Value)
        {
            Console.WriteLine($"{error.Key}: {message}");
        }
    }
}

Or you can just call EnsureValid, which throws a OpenTransSharp.Validation.ValidationException if not valid:

order.EnsureValid(serializer);

Setup Your Project

BMEcatSharp and OpenTransSharp can be used in any .NET Standard 2.0 compatible or .NET 6+ project.

Note: For complete samples of how to use this library, please see the code samples in this repository under

NuGet Packages

Depending on the desired integrations, you can pick 1 of 3 options:

A) If you want to integrate with ASP.NET Core, you can use the following NuGet packages:

Note: You need both if you want to read/edit/write/validate BMEcat®- and openTRANS®-documents in your project.

B) Otherwise, if you only want to integrate with Microsoft.Extensions.DependencyInjection, you can use the following NuGet packages:

Note: You need both if you want to read/edit/write/validate BMEcat®- and openTRANS®-documents in your project.

C) And finally, if you don't need any of the above integrations but only core funcationality, you can use the following NuGet packages:

ASP.NET Core Setup

Registering the ASP.NET Core integrations as shown here. These integrations add input formatters for model-binding and model-state handling.

OpenTransSharp
public void ConfigureServices(IServiceCollection services)
{
    services.AddOpenTransSharp(configure =>
    {
        // optional: register your custom UDX (user defined extension) types here
        configure.Serialization.IncludeUdxTypes = new[]
        {
            typeof(CustomData),
            typeof(CustomData2)
        };

        // optional: add custom xsd for validation
        configure.Serialization.XsdUris = new[] { new Uri($"file://{Environment.CurrentDirectory.Replace("\\", "/")}/CustomData.xsd") };

        // optional: add xml-file encodings that must be supported
        configure.Serialization.SupportedEncodings.Add("iso-8859-1");

        // optional: add xml-file content types that must be supported
        configure.Serialization.SupportedMediaTypes.Add("text/xml");

        // optional: if you need more control here the overrides can be customized
        configure.Serialization.ConfigureXmlAttributeOverrides = overrides =>
        {
            // add overrides
        };
    });
    services.AddControllers()
        // register for proper serialization over API
        .AddOpenTransSharpXmlSerializer();
    ...
}
BMEcatSharp
public void ConfigureServices(IServiceCollection services)
{
    services.AddBMEcatSharp(configure =>
    {
        // optional: register your custom UDX (user defined extension) types here
        configure.Serialization.IncludeUdxTypes = new[]
        {
            typeof(CustomData),
            typeof(CustomData2)
        };

        // optional: add custom xsd for validation
        configure.Serialization.XsdUris = new[] { new Uri($"file://{Environment.CurrentDirectory.Replace("\\", "/")}/CustomData.xsd") };

        // optional: add xml-file encodings that must be supported
        configure.Serialization.SupportedEncodings.Add("iso-8859-1");

        // optional: add xml-file content types that must be supported
        configure.Serialization.SupportedMediaTypes.Add("text/xml");

        // optional: if you need more control here the overrides can be customized
        configure.Serialization.ConfigureXmlAttributeOverrides = overrides =>
        {
            // add overrides
        };
    });
    services.AddControllers()
        // register for proper serialization over API
        .AddBMEcatSharpXmlSerializer();
    ...
}
Microsoft.Extensions.DependencyInjection Setup

If don't need ASP.NET Core but Microsoft.Extensions.DependencyInjection integration, the previous sample sections calling

  • services.AddBMEcatSharp(...) respectively
  • services.AddOpenTransSharp(...)

are the actual Microsoft.Extensions.DependencyInjection integration.

Core Functionality Setup

If you don't need any integrations, you can just simply use the core functionality.

BMEcatSharp
using BMEcatSharp;
...
var options = new BMEcatXmlSerializerOptions();
var serializerFactory = new BMEcatXmlSerializerFactory(options);
// from here on see previous usage examples
OpenTransSharp
using OpenTransSharp;
...
var options = new OpenTransXmlSerializerOptions();
var serializerFactory = new OpenTransXmlSerializerFactory(options);
// from here on see previous usage examples

Building this library

Prerequisites
  • Ensure you have .NET SDK 8.0+ installed (see https://dot.net)

  • Checkout this repository to your computer

  • Install Visual Studio 2022 if you want to build or develop with it

    Note: Visual Studio 2022 Community Edition is free for private use or small teams

Building with the command line
  1. Open command prompt and navigate to your checkout-directory
  2. Run dotnet build
Building with Visual Studio 2022
  1. Open OpenTransSharp.sln with Visual Studio 2022
  2. In main menu click Build > Build Solution (or press <kbd>CTRL+SHIFT+B</kbd>)

About BMEcat® and openTRANS®

In short:

  • BMEcat® is about product catalogs
  • openTRANS® is about ordering products (optionally from BMEcat® catalogs)

For more information about openTRANS® and BMEcat® see below.

Official Information
Wikipedia

https://de.wikipedia.org/wiki/OpenTRANS

https://de.wikipedia.org/wiki/BMEcat

Licenses

Copyright 2021-2023 David Rettenbacher

The license of this project is MPL 2.0. If not stated otherwise in individual files, this license applies to all files of this project.

For MPL 2.0 see the LICENSE.md file or browse to http://mozilla.org/MPL/2.0/ for the full license text. Additionally you can read up on this license on Wikipedia, and some Q&A on StackOverflow.

This project also uses specifications and XSDs from BMEcat®, openTRANS® and W3C®.

For BMEcat® see LICENSE-BMEcat.md, and for openTRANS® see LICENSE-openTRANS.md.

W3C® files contain a license header.

MPL 2.0 TLDR;
  • You can link this project statically or dynamically with your program, regardless of your program's license
    • You can distribute this library with your software under the terms of the GPL licenses
  • Contributions/modifications/forks must stay MPL 2.0

Disclaimer

This project has no affiliation with the official owners of BMEcat®, openTRANS®, or W3C®.
All trade, company and product names, trademarks or registered trademarks belong to their respective holders.

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 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 is compatible.  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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on BMEcatSharp.Microsoft.Extensions.DependencyInjection:

Package Downloads
BMEcatSharp.Microsoft.AspNetCore

ASP.NET Core support for BMEcatSharp

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.5 127 6/27/2024
1.0.5-pre1 115 5/16/2024
1.0.4 212 1/5/2024
1.0.3 162 12/26/2023
1.0.2 236 8/11/2023
1.0.1 243 4/10/2023
1.0.0 482 12/3/2022
1.0.0-pre3 204 4/24/2022
1.0.0-pre2 227 1/12/2022
1.0.0-pre1 259 6/20/2021

1.0.5
     - #19: Quotation document - email deserialization
     - #21: Fix serialization of DATETIME in CATALOG