Can I build something that works the same way as the ObsoleteAttribute?
13:05 18 Feb 2026

I'm building a set of classes for a rich domain model that receive services from IServiceProvider in their constructors, but are not intended to be newed up directly.

public class MyDomainEntity : DomainEntity
{
    private readonly ILogger _logger;

    [Obsolete("For IServiceProvider use only", true)]
    public MyDomainEntity(IServiceProvider serviceProvider, ILogger logger) : base(serviceProvider)
    {
        _logger = logger;
    }

    // ...
}

My colleague noted (correctly, in my opinion) that, while the message handles readability well enough, using [Obsolete] still feels like a kludge. So, I'd like to build a workalike, but with a more appropriate name.

Obviously I can't inherit from ObsoleteAttribute, because it's sealed, and it's clear from looking at the source and previous questions that whatever happens when it's used happens on the compiler side.

Is there a way to create this workalike? In case it matters, we're working in net10.0, and this would not need to be backwards compatible.

c# .net-10.0