In the “Program.cs” file, add
builder.Services.AddSingleton<IClassName, ClassName>();
var app = builder.Build();
Where ClassName is the class to inject and IClassName is the interface of the class
In the “Program.cs” file, add
builder.Services.AddSingleton<IClassName, ClassName>();
var app = builder.Build();
Where ClassName is the class to inject and IClassName is the interface of the class
The four basic principles of object-oriented programming are:
Abstraction: Model the necessary attributes and interactions of entities as classes to define an abstract representation of a system.
Encapsulation: Hide the internal state and functionality of an object and allow only access through a public set of functions.
Inheritance: Ability to create new abstractions based on existing abstractions.
Polymorphism: The ability to implement inherited properties or methods in different ways on various abstractions.
It is a series of principles and good practices that should be taken as a basis for software development to achieve a code that is cleaner, more maintainable, more scalable in the future and less prone to errors.
SOLID is the acronym for “Single Responsibility Principle“, “Open/Closed Principle“, “Liskov Substitution Principle“, “Interface Segregation Principle“, and “Dependency Inversion Principle“, where:
S: Single Responsibility Principle – Each module must have a single reason to change.
O: Open/Closed Principle – The code should be Open to extend it and add new features, and Closed to modifications, except those that must be made if an error is found.
L: Liskov Substitution Principle – A derived class must be able to be substituted for its base class.
I: Interface Segregation Principle – Several purpose-specific interfaces should be used, rather than a few large interfaces.
D: Dependency Inversion Principle – Must depend on abstractions, not concrete classes.
Private class
It is a class whose members can only be accessed by classes in the same environment.
Public class
It is a class whose members can be accessed by classes from any environment.
Protected class
It is a class whose members can only be accessed by the same class.
Abstract class
It is an incomplete class that defines the members that a base class must have.
It cannot be instantiated, it will only inherit.
Sealed class
It is a class that does not allow to be inherited, only instantiated
Private method
Is a method that is only accessible from the same class
Public method
Is a method that can be accessible from any class
Abstract methods
Is a method without implementation that must be implemented when inheriting the class
Virtual method
Is a method that can be overridden by inheriting the class
A Constant is an immutable value of a data type, its value cannot change during the execution of a program.
A ReadOnly is a variable of a data type whose value can only be defined in its declaration or in its constructor.
Go from “2013-10-20” to “20131020”
long n = Int64.Parse (DateTime.Now.ToString (“yyyymmdd”));
Tested on: Net framework 4.5
DateTime date1 = new DateTime(1970, 1, 9, 0, 0, 00);
DateTime date2 = DateTime.Now;
TimeSpan timeElapsed = new TimeSpan();
timeElapsed = date2 – date1;
Tested on: Net 4,7
using System.Data.SqlClient;
SqlParameter pParameterIn = new SqlParameter(“@ParameterIn“, “AnyValue”);
pParameterIn.Direction = System.Data.ParameterDirection.Input;
SqlParameter pParameterOut = new SqlParameter(“@ParameterOut“, -1);
pParameterOut.Direction = System.Data.ParameterDirection.Output;
var recordsAffected = _vmsDBContext.Database.ExecuteSqlCommand(
“sp_YourStoredProcedure @ParameterIn, @ParameterOut OUT”
, parameters: new[] {
pParameterIn
, pParameterOut
}
);
var answer = pParameterOut.Value;
Probado en:
Net 4.7