Naming Conventions

Assembly Naming

  • Kit.X.Abstractions - Classes/Interfaces that are referenced by multiple modules so that it doesn't take a dependency on the implementation.
  • Kit.X.Core - Used for a framework project when we have a module with the name Kit.X.
  • Kit.X - Default name.

IEnumerable vs IList

IEnumerable should be used when the generic type is an interface. This is because IEnumerable is convariant which means you can say:

public IEnumerable<IFoo> GetFoos() => new List<Foo>();

However the following won't work:

public IList<IFoo> GetFoos() => new List<Foo>();

If the above case is not true then IList should be used when calling the database. This forces you to execute the query (by saying ToList()) before returning the data.

IList also has the advantage that you can add/remove items from it, aswell as access the items via an index. This is why the majority of the collections against an entity use an IList.

Another general rule is to start with an IEnumerable and then change it to an IList when it is needed. If you use a narrower interface type such as IEnumerable instead of IList, you protect your code against breaking changes. The caller code can be changed in the future and your code won’t break that easily as it would if you had used IList.

The above is general rules for your return types but for passing data in, it is generally always beneficial to accept an IEnumerable as it allows you to pass in whatever type of collection you like.

Resources