This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IFunctionality1 | |
| { | |
| void DoStuff(IReadOnlyList<Person> persons, IReadOnlyList<Case> cases); | |
| } | |
| public interface IFunctionality2 | |
| { | |
| void DoMoreStuff(IReadOnlyList<Person> persons, IReadOnlyList<Case> cases); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IFunctionality1 | |
| { | |
| void DoStuff(IReadOnlyList<Person> persons, IReadOnlyList<Case> cases); | |
| } | |
| public interface IFunctionality2 | |
| { | |
| void DoMoreStuff(IReadOnlyList<Person> persons, IReadOnlyList<Case> cases); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //common variables used accross all functionalities | |
| var persons = personsRepo.GetPersons(filterParameters); | |
| var cases = casesRepo.GetCases(); | |
| //cases are merged here to update the first functionality, | |
| //the variable is shared between the 2 functionalities and so the other one bellow it is also changed | |
| cases = MergeRelatedCases(cases); | |
| //here goes functionality block1 for first functionality should be bellow | |
| //it uses the same variables declared and populated above as the functionality bellow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //common variables used accross all functionalities | |
| var persons = personsRepo.GetPersons(filterParameters); | |
| var cases = casesRepo.GetCases(); | |
| //here goes functionality block1 for first functionality should be bellow | |
| //it uses the same variables declared and populated above as the functionality bellow | |
| //here goes functionality block2 for the second functionality which also uses the variables declared above |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //there is an interface between the data access code and the actual functionality code, | |
| //this is a point of inflection which stops cascading changes, this should be injected in the constructor | |
| //but it would have made the example harder to read | |
| var personsRepo = ObjectFactory.GetInstance<IPersonsRepo>(); | |
| //bellow a separate component which fetches persons from the database is called: | |
| var persons = personsRepo.GetPersons(inputStatus); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //bellow main method that fetches data incline from the database | |
| //now updated to use DbContext with entity framework core | |
| //notice how the functionality code block1 was accidentally deleted | |
| //becaue it was mixed in with the data access code | |
| var persons = dbContext.Persons; | |
| if (!string.IsNullOrEmpty(inputStatus)) { | |
| persons = persons.Where(person => person.Status == inputStatus); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var persons = new List<Person>(); | |
| //bellow main method that fetches data incline from the database | |
| using (SqlConnection connection = new SqlConnection(connectionString)) | |
| { | |
| connection.Open(); | |
| using (SqlCommand command = new SqlCommand( | |
| "SELECT FirstName, LastName, Status FROM Persons ORDER BY FirstName", connection)) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WebRequest request = WebRequest.Create("http://www.bing.com"); | |
| request.Credentials = CredentialCache.DefaultCredentials; | |
| HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); | |
| Console.WriteLine(response.StatusDescription); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Authorize] | |
| public class AccountController : Controller | |
| { | |
| private IAspNetUserStore _aspNetUserStore; | |
| private ApplicationSignInManager _signInManager; | |
| private ApplicationUserManager _userManager; | |
| public AccountController(IAspNetUserStore aspNetUserStore) | |
| { | |
| _aspNetUserStore = aspNetUserStore; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void ConfigureAuth(IAppBuilder app) | |
| { | |
| // Configure the db context, user manager and signin manager to use a single instance per request | |
| app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); | |
| app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); | |
| // Enable the application to use a cookie to store information for the signed in user | |
| // and to use a cookie to temporarily store information about a user logging in with a third party login provider | |
| // Configure the sign in cookie | |
| app.UseCookieAuthentication(new CookieAuthenticationOptions |
NewerOlder