Skip to content

Instantly share code, notes, and snippets.

<unity>
<namespace name="Service.Class" />
<assembly name="Service" />
<container>
<register type="IOwnExpenseDService" mapTo="OwnExpenseDService" />
<register type="Model.Dal.IOwnExpenseDDal, Model" mapTo="Model.Dal.OwnExpenseDDal, Model" />
</container>
</unity>
@huanlin
huanlin / di-ex01-1.cs
Created August 13, 2014 01:09
Example code of DI book
interface IMessageService
{
void Send(User user, string msg);
}
class EmailService : IMessageService
{
public void Send(User user, string msg)
{
// 寄送電子郵件給指定的 user (略)
@huanlin
huanlin / NotificationManager
Last active August 29, 2015 14:10
Unity Example 6-1
public interface INotificationManager
{
void Notify(string to, string msg);
}
public class NotificationManager : INotificationManager
{
private readonly IMessageService _msgService = null;
// 從建構函式注入訊息服務物件。
@huanlin
huanlin / MessageService
Created November 25, 2014 09:39
Unity Example 6-2
public interface IMessageService
{
void SendMessage(string to, string msg);
}
public class EmailService : IMessageService
{
public void SendMessage(string to, string msg)
{
Console.WriteLine(" 透過 EmailService 發送郵件給 {0}。", to);
@huanlin
huanlin / GetRuntimePropertyName
Last active August 29, 2015 14:15
Get property name at runtime.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
namespace ConsoleApplication1
{
class Program
@huanlin
huanlin / gist:5428200
Last active December 16, 2015 11:29
Download web contents asynchronously using Thread class.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace Ex01_Console
{
class ThreadDemo
{
public static void Download(string[] urls)
using System;
using System.Threading;
class Program
{
static void Main(strin g[] args)
{
Thread t1 = new Thread(MyBackgroundTask);
t1.Start();
using System;
using System.Threading;
class Program
{
static void Main(string[] args)
{
Thread t1 = new Thread(MyBackgroundTask);
Thread t2 = new Thread(MyBackgroundTask);
Thread t3 = new Thread(MyBackgroundTask);
static void Main(string[] args)
{
Thread t1 = new Thread(MyBackgroundTask);
Thread t2 = new Thread(MyBackgroundTask);
Thread t3 = new Thread(MyBackgroundTask);
t1.Start("X");
t2.Start("Y");
t3.Start("Z");
class Program
{
static void Main(string[] args)
{
new SharedStateDemo().Run();
Console.ReadLine();
}
}