人生是一场不能存盘的RPG,我只能尽量多搞几个Screenshot

August 19, 2006

PetShop动态加载Pattern

Filed under: 代码学习

加载Order strategy,见Order class
1. Interface
public interface IOrderStrategy
{
void Insert(PetShop.Model.OrderInfo order);
}

2. Concrete class
public class OrderAsynchronous : IOrderStrategy
{
private static readonly PetShop.IMessaging.IOrder asynchOrder = PetShop.MessagingFactory.QueueAccess.CreateOrder();

public void Insert(PetShop.Model.OrderInfo order) {

asynchOrder.Send(order);
}
}

3.Factory
private static PetShop.IBLLStrategy.IOrderStrategy LoadInsertStrategy()
{

// Look up which strategy to use from config file
string path = ConfigurationManager.AppSettings[”OrderStrategyAssembly”];
string className = ConfigurationManager.AppSettings[”OrderStrategyClass”];

// Using the evidence given in the config file load the appropriate assembly and class
return (PetShop.IBLLStrategy.IOrderStrategy)Assembly.Load(path).CreateInstance(className);
}

4.web.Config
<add key=”OrderStrategyClass” value=”PetShop.BLL.OrderSynchronous”/>

Comments »

The URI to TrackBack this entry is: http://recordsome.blogsome.com/2006/08/19/p153/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham