---
title: "Extending Depender with your own custom dependency rules"
url: "https://osherove.com/blog/2008/7/5/extending-depender-with-your-own-custom-dependency-rules.md"
canonical: "https://osherove.com/blog/2008/7/5/extending-depender-with-your-own-custom-dependency-rules.html"
published: "2008-07-05T09:24:17"
updated: "2008-07-05T09:24:17"
tags: ["Agile", "Cool Tools"]
author: "Roy Osherove"
description: "In the previous post I introduced Depender , to help find dependency issues in your code (usually for testing). I've added extensibility to it so that you can write your own rules. If you download depender there will…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Extending Depender with your own custom dependency rules

By Roy Osherove July 5, 2008 In [Agile](https://osherove.com/blog/category/agile), [Cool Tools](https://osherove.com/blog/category/cool-tools)

**Historical article** · Originally published July 5, 2008; technical details may be outdated.

In the previous [post I introduced Depender](http://weblogs.asp.net/rosherove/archive/2008/07/05/introducing-depender-testability-problem-finder.aspx), to help find dependency issues in your code (usually for testing).

I've added extensibility to it so that you can write your own rules. If [you download depender](http://files.osherove.com/downloads/Depender.zip) there will also be a "src" directory in the zip file, which shows how the current rules it uses were built.

it should be really easy to created your own rules. Just :

- create your own assembly that has a name ending with ".Rules.dll"
- Implement IRule in your class, or, if you want to parse the contents of a method, inherit from MethodParserRule.

your rule will be automatically loaded according to the assembly naming convention and its interface.

here's how a simple rule looks:

public class FindOverridableMethodsRule:IRule
{
    public void Check(MethodInfo info, Dependency parent)
    {
        if (!info.IsFinal && (info.IsVirtual || info.IsAbstract))
        {
            parent.Add(new Dependency(string.Format(" {0}() can be overriden", info.Name)));
        }
    }

    public bool CanCheck(object obj)
    {
        return obj is MethodInfo;
    }

    public void Check(object obj, Dependency parent)
    {
        Check(obj as MethodInfo, parent);
    }
}

and here's a rule that parses the contents of a method:

public class FindStaticMethodCallRule : MethodParserRule
{
    protected override void DoChecks(MethodBase mehodBeingChecked, MethodBodyInfo methodBody, Dependency parent)
    {
        foreach (ILInstruction instruction in methodBody.Instructions)
        {
            if (instruction is InlineMethodInstruction)
            {
                InlineMethodInstruction line = instruction as InlineMethodInstruction;
                if (line.Method.IsStatic)
                {
                    string message =
                        string.Format("Static method call {0} on {1}", line.Method.Name,
                                      line.Method.ReflectedType.Name);

                    parent.Add(new ProblemDependency(message));
                }
            }
        }
    }

}

## More in Agile

[All posts in Agile](https://osherove.com/blog/category/agile)

- Jul 8, 2008

    ### [A sneak Preview of Typemock Racer : Thread Deadlock Finder](https://osherove.com/blog/2008/7/8/a-sneak-preview-of-typemock-racer-thread-deadlock-finder.html)

- Jul 6, 2008

    ### [Is Moq too poweful?](https://osherove.com/blog/2008/7/6/is-moq-too-poweful.html)

- Jul 5, 2008

    ### [Introducing Depender - Testability Problem Finder](https://osherove.com/blog/2008/7/5/introducing-depender-testability-problem-finder.html)

- Jul 3, 2008

    ### [TDD 5-day course\\workshop in Norway](https://osherove.com/blog/2008/7/3/tdd-5-day-courseworkshop-in-norway.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
