When you lose face because you made the wrong Lifestyle choice.

Aaron

Gravypower

  • https://blog.gravypower.net
  • @gravypower
  • https://github.com/gravypower

 

The invasion of Trump

The night was dark and stormy, the dunney light was dim, I heard a crash and then a splash my gosh he has fallen in.

The invasion of Trump

The invasion of Trump

The invasion of Trump

The invasion of Trump

The invasion of Trump

SOLID Principles of Object Oriented Design. D is for Dependency Inversion

Object Lifetime Management

  • Transient
  • Scoped
  • Singleton🥃

Object Lifetime Management

  • Transient
  • Scoped
  • Singleton🥃

A new instance every time.

Object Lifetime Management

  • Transient
  • Scoped
  • Singleton🥃

One instance for the life of the application.

Object Lifetime Management

  • Transient
  • Scoped
  • Singleton🥃

A new instance per scope.

That's great Aaron, but how does trump fit in?

Let me try and explain

using a chalk board and a note book

Colour: blue

Text: Join Generic Site today

Image: Glasses

Join Generic Site today

Colour: Black

Text: Everyone says this is the best site

Image: Dancing

Everyone says this is the best site

Person A

Person B

Everyone says this is the best site

Join Generic Site today

Person A

Person B

Person C

What's the moral of this story?

  • Don't use Singletons🥃
  • Be careful with Scoped
  • Your default position should be transient

Well why have the other Lifestyles?

  • Configuration for the running application
  • Logging
  • Mapping to something IRL like a drone
  • If you are directed to by a library you are using

Singleton🥃

Well why have the other Lifestyles?

  • Database connection
  • Mutable operation for some scope ;)
  • There is a need to control the disposal of an object
  • If you are directed to by a library you are using

Scoped

Link to my Blog

When you lose face because you made the wrong Lifestyle choice.

By Aaron Job

When you lose face because you made the wrong Lifestyle choice.

  • 213