DEV Community

Haku B.
Haku B.

Posted on • Edited on

.NET learning notes

public abstract class TaskBase<TSummaryInfo> : ProcessorBase where TSummaryInfo : class, new() 
{ 
  // code 
}
Enter fullscreen mode Exit fullscreen mode

An abstract class TaskBase which declares TSummaryInfo type and inherits ProcessorBase class.
where TSummaryInfo : class means the TSummaryInfo type needs to be a class. new() means it has a parameter-less construction.


Lazy instantialization

namespace Project.Controllers {
  public class SomeController : Controller {

    // only instantialize when the instance is needed in the methods of this class
    private ISomeService _someService;
    private ISomeService SomeService => _someService ?? (_someService = new SomeService(new SomeRepository()));


    // do not instantialize in constructor, so that the instances won't be created every time when the class is constructed, unless they are called as parameters from below method.
    public someController () {}

    public void someClass(SomeService){
      //...code
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Naming Convention:

  • _someService: "back-end" variables
  • SomeService: parameter of methods, or just the class

Top comments (0)