顯示具有 C# 標籤的文章。 顯示所有文章
顯示具有 C# 標籤的文章。 顯示所有文章

2013年12月5日 星期四

IoC, DI, Factory, Reflection

IoC: Inversion of Control
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

image

All dependencies will be installed too

image

After installation, you will several references have been included

image

 

On-line document of Service Stack

http://servicestack.net, click the Documentation button

image

Click Create your first webservice

image

This page is for non MVC application, so scoll down to the link for MVC

image

Click the link below:

https://github.com/ServiceStack/ServiceStack/wiki/Run-servicestack-side-by-side-with-another-web-framework.

image

Copy the content of Web.config

image

Other steps

image

 

Implement in Visual Studio

image

image

image

image

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

image

Using the service that we just created

image

 

Testing on Web Service

The default web site URL has error, it is no doubt

image

Has to add “/api” to see available web services, but it’s still fail so far

image

Check the error message, we forgot to new an AppHost() in Application_Start() in Global.asax

image

So add the code, “new ProteinTrackerAppHost().Init();” in Application_Start() function

image

Now it works, and showing following screen.

One operation shows, Hello. It supports different format, XML, JSON, JSV, CSV, …etc.

Click JSON, for example.

image

Two routes are available for this service

image

Using /api/hello/xxx to consume the web service

image

In json format

image

In xml format

image

2013年10月11日 星期五

ServiceStack.Redis, C#

https://github.com/ServiceStack/ServiceStack.Redis

Redis Client API Overview

image

 

4 Types of RedisClients

image

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

image

image

 

Example 1, IRedisNativeClient

image

image

 

Example 2, IRedisClient

image

image

image

image

 

Example 3, IRedisTypedClient

image

image

image

image

image

 

Example 4, Transcation

image

image

image

 

Example 5, Pub and Sub

image

image

image

2013年9月17日 星期二

ASP.NET SignalR – Clients

Outline

1. Hub Consumers

2. jQuery Clients

3. .NET Clients

 

1. Hub Consumers

image

image

image

 

2. jQuery Client

image

First approach:

jQuery with Proxy – part I

image

image

image

Demo 1 – UI preparation

image

image

image

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

image

image

image

image

 

jQuery with Proxy – part II

image

image

 

jQuery with Proxy – part III

image

image

image

image

 

Demo 3 – Chat.js

image

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

image

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

 

image

 

Demo – Join Group

image

image

image

image

image

Demo – Monitor (test fail)

image

image

image

image

 

Second approach:

jQuery without Proxy File

image

image

image

image

Demo

image

image

image

 

3. .NET Client

image

image

image

image

Demo – Win Form

image

image

image

image

image

 

Summary

image