看看依赖注入和容器的作用、和为何要用。
我觉得自己动手做,再学框架,会事半功倍。以下是虚构场景,部分是内部培训资料,有错误请赐教。
先看看下面代码,我从数据库拿点东西出来,做些业务运算(这里是两个 decimal 相乘而已),然后显示:
Code Snippet
string connectionString = @"data source=localhost\sqlexpress;initial catalog=amort;integrated security=true;"; StringBuilder sb = new StringBuilder(); using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); string command = "SELECT ItemCode,Quantity,UnitPrice FROM FIFO_Detail"; SqlCommand sqlcommand = new SqlCommand(command, conn); SqlDataReader dr = sqlcommand.ExecuteReader();