2013年12月5日 星期四
IoC, DI, Factory, Reflection
DI: Dependency Injection
OCP: Open Close Principle, open for extend; close for modify
DI Implement: Constructor Injection, Setter Injection, Interface Injection
Factory
Reflection
IoC Container, IoC Framework: StrcutureMap, Microsoft Unity, Spring.NET
References:
http://itworktor.blog.163.com/blog/static/1752030292010112292449841/
http://dev.pete.tw/2011/04/inversion-of-control-pattern.html
http://www.dotblogs.com.tw/joysdw12/archive/2012/11/26/85081.aspx
2013年10月13日 星期日
Web Services by Using Service Stack Web Service Framework
Install Service Stack from NuGet
All dependencies will be installed too
After installation, you will several references have been included
On-line document of Service Stack
http://servicestack.net, click the Documentation button
Click Create your first webservice
This page is for non MVC application, so scoll down to the link for MVC
Click the link below:
Copy the content of Web.config
Other steps
Implement in Visual Studio
Add “Api” folder and one class, “HelloService.cs”.
Code separate into 3 parties:
1. Service
2. Request
3. Response, the name is always requestName+Response
Using the service that we just created
Testing on Web Service
The default web site URL has error, it is no doubt
Has to add “/api” to see available web services, but it’s still fail so far
Check the error message, we forgot to new an AppHost() in Application_Start() in Global.asax
So add the code, “new ProteinTrackerAppHost().Init();” in Application_Start() function
Now it works, and showing following screen.
One operation shows, Hello. It supports different format, XML, JSON, JSV, CSV, …etc.
Click JSON, for example.
Two routes are available for this service
Using /api/hello/xxx to consume the web service
In json format
In xml format
2013年10月11日 星期五
ServiceStack.Redis, C#
https://github.com/ServiceStack/ServiceStack.Redis
Redis Client API Overview
4 Types of RedisClients
You can choose the layer of abstraction to work with
1. ICacheClient:
2. IRedisNativeClient: same command in C# and native client but in binary data format
3. IRedisClient: higher level of redis client
4. IRedisTypedClient:
Using NuGet to Install
Example 1, IRedisNativeClient
Example 2, IRedisClient
Example 3, IRedisTypedClient
Example 4, Transcation
Example 5, Pub and Sub
2013年9月17日 星期二
ASP.NET SignalR – Clients
Outline
1. Hub Consumers
2. jQuery Clients
3. .NET Clients
1. Hub Consumers
2. jQuery Client
First approach:
jQuery with Proxy – part I
Demo 1 – UI preparation
1. Must include both javascript files, jQuery.js & SignalR.js BEFORE 2. SignalR/Hubs
2. Must include SignalR/Hubs
3. Include personal javascript file
Demo 2 – SignalR Utilities (signalr.exe) to generate server.js file
jQuery with Proxy – part II
jQuery with Proxy – part III
Demo 3 – Chat.js
Explain above 3 points:
1. chat.client.newMessage –> newMessage() is a client event method that can be called from server side. Define client behavior first
2. Once button click, trigger server side event by this line of code chat.server.sendMessage(xxx), so all clients will run client side event newMessage() which defined in previous step
3. Enforce to use longPolling as transport negociation protocal and start hub connection
Demo – Join Group
Demo – Monitor (test fail)
Second approach:
jQuery without Proxy File
Demo
3. .NET Client
Demo – Win Form