开发者

Which application layer should dispose DataContext (Silverlight WCF RIA)

开发者 https://www.devze.com 2023-04-07 18:54 出处:网络
My silverlight application is design with 3 layers at server side Interface Layer - This layer contain only interface that bridge between silverlight client and RIA service. What I do in this layer

My silverlight application is design with 3 layers at server side

  1. Interface Layer - This layer contain only interface that bridge between silverlight client and RIA service. What I do in this layer is send ObjectContext (DataContext that generated from DAL) which create automatically in this layer and send it do Business Logic Layer
  2. Business Logic Layer - All of class in this layer has overload constructor which is DataContext that send from Interface Layer. All logic is doing in this layer, such as, filter result, validate data, etc.
  3. Data Access Layer - Pure Entity Framework.

Current implementation of Business Layer is all class implement IDisposable interface which call Dispose method of DataContext inside it, as example below.

开发者_Python百科MyServerInterfaceLayer.cs

using (var myBusinesessLogicLayer = new MyBLL(this.DataContext1, this.DataContext2))
{
    myBusinesessLogicLayer.DoSomething();
}

MyBLL.cs

public void DoSomething()
{
    // ..
}

public void Dispose()
{
    // dispose all datacontext inside Dispose method of BLL
    this._dataContext1.Dispose();
    this._dataContext2.Dispose();
}

Currently I have problem when I have 2 class in Business Layer, MyBLL1 and MyBLL2. MyBLL1 need to call some method in MyBLL2 now I send DataContext from MyBLL1 to MyBLL2 after it out of scope of MyBLL2 it will dispose. So I want to know what layer should I call DataContext.Dispose?

0

精彩评论

暂无评论...
验证码 换一张
取 消