Wednesday, July 9, 2014
Wednesday, July 2, 2014
Monday, June 30, 2014
What Makes a Good Programmer?
http://henrikwarne.com/2014/06/30/what-makes-a-good-programmer/
1. PROBLEM DECOMPOSITION
2. SCENARIO ANALYSIS
3. NAMING
1. PROBLEM DECOMPOSITION
2. SCENARIO ANALYSIS
3. NAMING
Thursday, June 26, 2014
How to implement Dependency Injection by Autofac in MvcApplication class (ASP.NET MVC Global.asax)?
There are a lot of code examples for how to implement Dependency Injection for controller in ASP.NET MVC, but not too much about MvcApplication class in ASP.NET MVC.
Following is my implementation for Dependency Injection in MvcApplication class
Following is my implementation for Dependency Injection in MvcApplication class
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
RegisterDependencies();
//pass service into other class that need this service
var c = new OtherClassNeedService(_IYourService);
}
private AutofacDependencyResolver IoCcontainer { get; set; }
private IYourService _IYourService
{
get
{
if (IoCcontainer == null) return null;
return IoCcontainer.ApplicationContainer.Resolve();
}
}
public void RegisterDependencies()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterType()
.As(); //.InstancePerHttpRequest(); if added InstancePerHttpRequest, will get error: No scope with a Tag matching 'httpRequest' is visible from the scope in which the instance was requested.
IContainer container = builder.Build();
var aResolver = new AutofacDependencyResolver(container);
DependencyResolver.SetResolver(aResolver);
IoCcontainer = aResolver;
}
protected void Application_End(object sender, EventArgs e)
{
IoCcontainer.ApplicationContainer.Dispose();
}
}
Thursday, June 19, 2014
How to get dropdown list from html by Html Agility Pack
private ListNeed to add HtmlNode.ElementsFlags.Remove("option");GetDropdownList(string HtmlSource, string selectName) { HtmlDocument doc = new HtmlDocument(); HtmlNode.ElementsFlags.Remove("option"); doc.LoadHtml(HtmlSource); return doc.DocumentNode.SelectNodes(string.Format("//select[@name='{0}']//option", selectName)).Select(v => v.Attributes["value"].Value).ToList(); }
before loading html source.
Subscribe to:
Posts (Atom)
