tags:

views:

586

answers:

3
+8  A: 

Interfaces can't have static methods. A class that implements an interface needs to implement them all as instance methods. Static classes can't have instance methods. QED.

Joe White
+2  A: 

Maybe our experience will help. Rather than SqlRepository as a static class, we use Spring for injection and created a static repository property on our entities:

public class PartEntity : inheritence...
{
    public static IPartRepository Repository
    {
        get { return Spring.Stuff.To.Get.Right.Repository(); }
    }
}

This way we can swap out the implementation and callers always know where to get it:

var p = PartEntity.Repository.Get(id);
n8wrl
+2  A: 

By definition, interfaces create a contract for instances to fulfill. Since you cannot instantiate a static class, static classes cannot implement interfaces.

There is no need to have a static repository. Simply make it non-static and instantiate it when you need it.

JoshJordan