DEV Community

Szymon Hałucha
Szymon Hałucha

Posted on • Edited on

Default Interface Implementation or Mix-in design pattern in the C#

In a recent project I wrote, I needed to implement the traits or mix-in design pattern. The C# language has a built-in implementation of the traits pattern hiding under the name Default Interface Implementation, but it is in the experimental stage and is not compatible with the netstandard2.0 standard. For the purpose of this project, I created a simple package implementing the mix-in pattern, which is compatible with netstandard2.0 and C# 7.3+.

How to use it?

[Minerals.AutoMixins.AddMixin(typeof(ExampleMixin1), typeof(ExampleMixin2))]
public partial class ExampleClass
{
    // Implementation here...
}

[Minerals.AutoMixins.GenerateMixin]
public class ExampleMixin1
{
    // Implementation here...
}

[Minerals.AutoMixins.GenerateMixin]
public class ExampleMixin2
{
    // Implementation here...
}
Enter fullscreen mode Exit fullscreen mode

GitHub: https://github.com/SzymonHalucha/Minerals.AutoMixins
NugGet: https://www.nuget.org/packages/Minerals.AutoMixins/

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay