Skip to main content

Posts

Events and Delegates

Class with 2 events  public class Worker     {         // Created 2 events         public event EventHandler OnCompleted;         public event EventHandler<WorkerArgs> InBetween;         public void DoWork(int age, string address)         {             for (int i = 0; i < age - 1; i++)             {                 Thread.Sleep(1000);                  // Either this way                 //var del= InBetween as EventHandler<WorkerArgs>;                 //if (del != null) del(this,new WorkerArgs(i,address));                 // Or Directly             ...

Open Closed -

Open Closed SOLID was written during the early 90's when changing the code and republishing took a lot of time. Now it just takes minutes to redeploy the code. Also nowadays with the agile way of developing software changes are bound to happen. We often have this tendency to try to gold-plate things or say, well, we have this specific problem, but if we just set a specific flag here or add an input argument to this function here , we could make this specific thing that we're trying to do into some sort of general purpose solution, and the problem with that is that it tends to lead to coupling and complexity.  Reused Abstractions Principle. So this is not a principle that's a part of the five SOLID principles, but it's very much related to the five SOLID principles, and basically it says, if you have abstractions, in this case, if you have interfaces or abstract-based classes, and those abstractions are not being reused by being implemented by various different c...

Single responsibility

Single responsibility THINGS THAT BELONG TOGETHER SHOULD STAY TOGETHER What we're really aiming for when we're talking about SOLID code is supple code, code that's pliable, code that you can shape into different forms and where you can change the shape if it turns out that the original shape that you had in mind doesn't really correctly address the problem at hand. And this is very important, because you almost never have all the requirements up front. Even if you think you have all the requirements up front for a piece of software that you're programming, requirements change as you go along, and the point of writing SOLID code is to make the code so supple, so pliable, that when requirements change, you can also change the code to fit the new requirements. The purpose of SOLID is to make you more productive by making the code more maintainable. If the design is rigid, it signifies that does not accept change. We define a responsibility as a reason to change. ...

Extension Method To Compare 2 Objects

Extension Method To Compare 2 Objects https://stackoverflow.com/questions/10454519/best-way-to-compare-two-complex-objects  or use this public static class ObjectComparer {     public static bool CompareObj(this object source, object destination)     {         if (!source.GetType().Equals(destination.GetType()))             return false;         var properties = source.GetType().GetProperties();         foreach (var item in properties)             if (!item.GetValue(source, null).Equals(item.GetValue(destination)))                 return false;         return true;     } } Usage Create 2 classes. class Program     {         static void Main(string[] args)         {       ...

SignIn Using Facebook Aspnet core 2.2

SignIn Using Social Logins Aspnet core 2.2 https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-2.2   https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/facebook-logins?view=aspnetcore-2.2 Follow the above link to create an app and get the clientId and secret from google. and AppId and App secret from facebook. Facebook Alone To integrate login using facebook alone just add the below lines  In  ConfigureServices  method  services.AddAuthentication(op=> {                 op.DefaultChallengeScheme = FacebookDefaults.AuthenticationScheme;                 op.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;                 op.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; ...

SignalR with Aspnet core 2.2 and angular6

SignalR with Aspnet core 2.2 and angular6 The SignalR server library is included in the  Microsoft.AspNetCore.App.  Next we need to configure our wepapi  to use it.  in configureservices() section add  services.AddCors(); in the configure method add app.UseCors(builder => builder                 .AllowAnyHeader()                 .AllowAnyMethod()                 .SetIsOriginAllowed((host) => true)                 .AllowCredentials()             ); this is different from core 2.1 as allowanyorigin is not supported with allowcredentials. So we need to either specify which origins to allow for eg: app.UseCors(builder =>             {                 builder.WithOrigin...

Code First Vs Database First (Ef Core 2.1)

Code First Vs Database First (Ef Core 2.1) Seeding the DB          protected override void OnModelCreating(ModelBuilder modelBuilder)         {             base.OnModelCreating(modelBuilder);             modelBuilder.Seed();          } public static class ModelBuilderExtensions     {         public static void Seed(this ModelBuilder modelBuilder)         {             modelBuilder.Entity<Person>().HasData(                 new Person { Id=1,Name = "Anish", Address = "mvlk" }             );             modelBuilder.Entity<Book>().HasData(                 new Book { BookId = 1, AuthorId = 1, Titl...