Andre Lopes
1 min readNov 10, 2019

Thanks for the insights :)

I didn’t go too deep in FluentValidation to not make this article longer.

As for the ICollection, I avoid using virtual properties to make sure that I will not enable Lazy Loading. And I always initialize collections in the constructor too avoid getting a System.NullReferenceException and can . For example, if I create a new instance of Artist like below:

var a = new Artist();

without initializing Musics collection in the constructor, and try to add a new music to the list, even with the virtual key I will get an exception.

a.Musics.Add(new Music()); // Throws System.NullReferenceException

Or try to iterate throught for some reason:

foreach(var music in a.Musics)
{
// run some code
}

Unless I assign a new list of musics to it, like this:

var musics = new Collection();
musics.Add(new Music());
a.Musics = musics;

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Written by Andre Lopes

Full-stack developer @ Tesla | Public Speaker | AWS | Terraform | Serverless | Gamer | Eternal Geek 🤓

No responses yet

Write a response