Giter Club home page Giter Club logo

crosscutting's Introduction

CrossCutting

Generic utilities and other stuff, usable in any layer of any solution. We're targeting .NET Standard 2.0, so you can even use .NET Framework 4.x if you want to.

This repository consists of the following packages:

Package name Description
CrossCutting.Common Provider for system date and user name, some useful extension methods on System.Object and System.String, and the Result class
CrossCutting.Common.Testing Helps you test constructors on null checks
CrossCutting.Data.Abstractions Abstraction for executing database commands using System.Data namespace (IDbConnection and IDbCommand)
CrossCutting.Data.Core Default implementation of database commands
CrossCutting.Data.Sql Extension methods for working with database commands in System.Data namespace (IDbConnection)
CrossCutting.DataTableDumper Produces flat-text data tables from objects
CrossCutting.Utilities.ObjectDumper Produces readable flat-text representation from objects, for use in logging
CrossCutting.Utilities.Parsers Parser for pipe-delmited data table strings, TSQL INSERT INTO statements, function strings, math expressions and formattable strings (dynamic interpolated strings)
System.Data.Stub Stubs for System.Data interfaces like IDbConnection, IDbCommand and IDataReader

Using NSubstitute or Moq as mock factory for CrossCutting.Common.Testing

To use NSubstitute as a mock factory for the code in CrossCutting.Common.Testing, create a test helper project within your solution, and add the following code:

    public static void ShouldThrowArgumentNullExceptionsInConstructorsOnNullArguments(
        this Type type,
        Func<ParameterInfo, bool>? parameterPredicate = null,
        Func<ParameterInfo, object?>? parameterReplaceDelegate = null,
        Func<ConstructorInfo, bool>? constructorPredicate = null)
        => ShouldThrowArgumentNullExceptionsInConstructorsOnNullArguments(
            type,
            t => t.CreateInstance(parameterType => Substitute.For(new[] { parameterType }, Array.Empty<object>()), parameterReplaceDelegate, constructorPredicate),
            parameterPredicate,
            parameterReplaceDelegate,
            constructorPredicate);

You can easily replace NSubstitute with Moq, if you want, by changing the factory delegate argument to this:

t => t.CreateInstance(parameterType => ((Mock)Activator.CreateInstance(typeof(Mock<>).MakeGenericType(parameterType))).Object, parameterReplaceDelegate, constructorPredicate),

Upgrade from 2.x to 3.0

There has been a breaking change in the Result class, which lead to a new major version. To port the old code, you can fix most errors by replace this:

Result<([^>]+)>\.([^(]+)\(

With this:

Result.$2<$1>(

crosscutting's People

Contributors

pauldeen79 avatar

Watchers

 avatar

crosscutting's Issues

Add new pipeline processor

Create a project for pipeline processing.
Characteristics:

  • Allows to create a pipeline with steps (features), which are registered using an order
  • No dependency to a DI framework, because by building the pipeline you add features using instances instead of types
  • Makes it easy to create pluggable pipelines, for example in ModelFramework or DataFramework
  • Adds an extra layer of abstraction to pipeline processing

Signature:
void Process<TModel, TContext>(TModel model, TContext context)

Desired code:
new ProcessingPipeline()
.AddFeature(new AddPropertiesFeature()[, order])
.AddFeature(new SomeFeature()[, order])
.RemoveFeature()
.ReplaceFeature(MyReplacementFeature[, order])
.Build()
.Process(model, new MySettings(...));

IFeature<TModel, TContext>: void Process(ProcessingContext<TModel, TContext> context)
ProcessingContext:
TModel Model { get; }
TContext Context { get; }

You can create some specific pipelines, like ClassBuilderPipeline(), which is just a predefined set of features within a pipeline.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.