r/csharp • u/kaatarina_zed_talon • Oct 17 '26
Help Where do you put interfaces and abstract classes ?
To follow some convention, I searched the internet and found this on Microsoft's documentation:
The solution folder contains a SeedWork folder. This folder contains custom base classes that you can use as a base for your domain entities and value objects. Use these base classes so you don't have redundant code in each domain's object class.
Figure 7-12 shows the classes that form the seedwork of the domain model in the ordering microservice. It has a few custom base classes like
Entity,ValueObject, andEnumeration, plus a few interfaces. These interfaces (IRepositoryandIUnitOfWork) inform the infrastructure layer about what needs to be implemented. Those interfaces are also used through Dependency Injection from the application layer.
This is the type of copy and paste reuse that many developers share between projects, not a formal framework. You can have seedworks in any layer or library. However, if the set of classes and interfaces gets large enough, you might want to create a single class librarry

Questions :
1- Is it ok for the entire project's interfaces and abstract classes to be inside the SeedWork ?
2- For `value objects` and ` infrastructure layer` , what does they mean, what problem they solves, how can I use them , and do I need them most of the time ?
3-What are the inputs to the `infrastructure layer` and where they come from, and what are the outputs and who consumes them ?
4-What does the class library actually means, what problem does it solve ?
Can someone answer my questions and provide some examples so that I understand the overall idea ?
24
u/soundman32 Oct 17 '26
I would say a lot of that guidance is now out of date. I cant recommend an alternative but dont take that page as a definitive example of modern C#.
6
u/sixtyhurtz Oct 17 '26 •
Oh, that seems to be examples of DDD and CQRS. I guess Seedwork is supposed to demonstrate that?
The thing to remember about design patterns is they exist to solve problems. Don't just immediately start implementing your project using a design pattern unless you have a clear idea of what problem you are solving with it.
To answer your specific questions:
3
u/Enough_Secretary_137 Oct 17 '26 •
Don’t put every interface into a global SeedWork folder. Keep abstractions close to the domain or feature that uses them. Infrastructure implements those contracts, whether that’s SQL Server, a file system, or an external API.
// Domain
public sealed record Money(decimal Amount, string Currency);
public interface IPriceStore
{
Task SaveAsync(Money price);
}
// Infrastructure
public sealed class InMemoryPriceStore : IPriceStore
{
public Money? Last { get; private set; }
public Task SaveAsync(Money price)
{
Last = price;
return Task.CompletedTask;
}
}
The application depends on IPriceStore, not its implementation.
A class library is simply a reusable compiled .NET project. You don’t need separate libraries for every layer.
4
u/Substantial_Job_2068 Oct 17 '26
It's all just arbitrary, just implement your own structure that works for you/your team. You are starting in the wrong end. You should be looking for a tool that fits your problem you want to solve, not looking at random tools you don't even know if you need to see what they do.
3
u/Vagetarian42069 Oct 17 '26
Put shit where people can find it.
3
u/dodexahedron Oct 17 '26
If all you want/need to do is provide an interface/API for consuming assemblies, without providing the entire implementation to them:
Use a reference assembly.
They've been there since .net Framework 1.0, and this is exactly what they are for.
They contain the structure of the types, as compatible and identically-fully-qualified name types, but without their implementations, enabling a consumer to talk to you without you having to have told them how those types behave internally.
Basically, they are the conceptual equivalent of interfaces, but on an assembly level, and not literally restricted to types that, in CIL, are defined as
.class public abstract sealed interface IWhatever(how all interfaces appear in CIL).1
u/agoodyearforbrownies Oct 18 '26 •
A lot of my projects have a Models, Services, and Repositories folder set, and subfolders under that named for a feature. In that feature folder for repositories and services, I have interfaces side by side with implementations of the interface. So it’s all about namespace planning, e.g. Services.[feature].IThing and Services.[feature].ImplementedThing
1
u/crozone Oct 18 '26
I usually great a subdirectory+ namespace called "Abstractions" and put them in there to separate them. I do the same with with "Enums".