This sample is a minimal consumer project that references the local analyzer project directly.
The project itself is intended to build without DependencyContractAnalyzer warnings.
ProvidesContract+RequiresDependencyContractContractTarget+RequiresContractOnTargetContractScope+RequiresContractOnScopeContractHierarchy- dependency extraction through constructor parameters, method parameters, property types,
newexpressions, and static member usage
dotnet build samples/DependencyContractAnalyzer.Sample/DependencyContractAnalyzer.Sample.csprojThe sample README keeps a few minimal invalid snippets here instead of shipping them in the runnable project.
DCA001 through a method parameter:
public interface IUnreliableClock
{
int ReadHour();
}
[RequiresDependencyContract(typeof(IUnreliableClock), "thread-safe")]
public sealed class InvalidMethodParameterExample
{
public void Execute(IUnreliableClock clock)
{
}
}DCA001 through a target requirement:
[ContractTarget("repository")]
public sealed class SlowRepository
{
}
[RequiresContractOnTarget("repository", "thread-safe")]
public sealed class InvalidTargetExample
{
public SlowRepository Create() => new();
}