question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

C# 11 required property support

See original GitHub issue

Now that C# 11 has required properties, are there plans for SimpleInjector to support auto-injecting those?

Issue Analytics

  • State:open
  • Created 8 months ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
GeraldLxcommented, Feb 3, 2023

SimpleInjector has always been about writing clean code. I always feel like a journey back in time, when I have to use the “new” Microsoft Dependency Injection.

There are sometimes reasons to use property injection. I used basically the same code I posted before with my own DependencyAttribute (the required keyword did not exist at that time) in project with a lot of legacy code heavily using inheritance.

Perhaps a compromise would be to have a fitting PropertySelectionBehavior included and a nice extension method or boolean property in the options to activate it?

0reactions
mikernetcommented, Feb 3, 2023

composition over inheritance

Generally speaking yes of course, but not always possible or desirable when working with view models in MVVM desktop scenarios.

Read more comments on GitHub >

github_iconTop Results From Across the Web

required modifier - C# Reference
The required modifier is available beginning with C# 11. The required modifier enables developers to create types where properties or fields ...
Read more >
Introducing C#11: Required properties
C# 11 improves the initialization of objects and struct. Marking one or more properties as mandatory on initialization is now possible and will ......
Read more >
Introducing the C# 11 Required Keyword - The New Dev's Guide
Unlike past solutions, the required keyword makes the compiler responsible for enforcing setting of non-nullable properties. This ultimately ...
Read more >
C# 11 required members
C# 11 proposes the new keyword required that can apply to an instance property or an instance field declaration within a class ,...
Read more >
The Required Keyword in C# 11
The required keyword fixes object initializers and can potentially change how you implement classes in C#. · When working with Nullable Reference ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found