Skip to content

Instantly share code, notes, and snippets.

@mvirkkunen
Created December 23, 2014 17:23
Show Gist options
  • Save mvirkkunen/f5f3927dbbb87a54941c to your computer and use it in GitHub Desktop.
Save mvirkkunen/f5f3927dbbb87a54941c to your computer and use it in GitHub Desktop.
Constructor injection in C# now vs. C# 6
// C# now
// Types mentioned 2 times, names mentioned 4 times
public class DerpController
{
readonly ISomeService Some;
readonly IAnotherService Another;
public DerpController(ISomeService some, IAnotherService another)
{
Some = some;
Another = another;
}
}
// C# 6
// Types mentioned 2 times, names mentioned 3 times
public class DerpController6(ISomeService some, IAnotherService another)
{
ISomeService Some { get; } = some;
IAnotherService Another { get; } = another;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment