Skip to content

Instantly share code, notes, and snippets.

View Alecu100's full-sized avatar

Andrei Alecsandru Neculai Alecu100

View GitHub Profile
public interface IFunctionality1
{
void DoStuff(IReadOnlyList<Person> persons, IReadOnlyList<Case> cases);
}
public interface IFunctionality2
{
void DoMoreStuff(IReadOnlyList<Person> persons, IReadOnlyList<Case> cases);
}
public interface IFunctionality1
{
void DoStuff(IReadOnlyList<Person> persons, IReadOnlyList<Case> cases);
}
public interface IFunctionality2
{
void DoMoreStuff(IReadOnlyList<Person> persons, IReadOnlyList<Case> cases);
}
//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
//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
//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);
//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);
}
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))
{
WebRequest request = WebRequest.Create("http://www.bing.com");
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
Console.WriteLine(response.StatusDescription);
[Authorize]
public class AccountController : Controller
{
private IAspNetUserStore _aspNetUserStore;
private ApplicationSignInManager _signInManager;
private ApplicationUserManager _userManager;
public AccountController(IAspNetUserStore aspNetUserStore)
{
_aspNetUserStore = aspNetUserStore;
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