This is a migrated thread and some comments may be shown as answers.

Define a global ObjectScope

3 Answers 110 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hessner
Top achievements
Rank 2
Hessner asked on 27 Jan 2009, 07:18 PM

I define an objectscope in the BeginRequest event, like this:

  app.Context.Items["ObjectScopeProvider"] = Database.Get("MyDatabaseConnection").GetObjectScope();

 

And use it anywhere I want during the current request, like this:

 
  IObjectScope osp = (IObjectScope) Context.Items["ObjectScopeProvider"];

I do not use any cleanup code - at all.

1. Maybe I should do some "cleaning" up?
2. Do you see any "danger" in this super simple setup?

3 Answers, 1 is accepted

Sort by
0
Dimitar Kapitanov
Telerik team
answered on 28 Jan 2009, 05:44 PM
Hello Hessner,
Yes, handling the IObjectScope should be done properly as it must be disposed in some way in the end of the request/page life-cycle. You can take a look at Simplifying OpenAccess Scope in ASP.NET with HttpModule - one of the popular techniques for handling IObjectScope in web applications. Hope this helps.

Regards,
Dimitar Kapitanov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Hessner
Top achievements
Rank 2
answered on 28 Jan 2009, 06:51 PM
I could easy dispose it in the EndReqest event(app.Context.Items.Remove("ObjectScopeProvider")), but if the following are true:

"Context.Items is available for all components (including the page) through the entire current request response lifecycle"

then why should I have to,- the Context.Items are automaticly "flushed" when the request end, as I understand it?

Are you suggesting that I execute this code in EndRequest event:
 IObjectScope osp = (IObjectScope) Context.Items["ObjectScopeProvider"];
 osp.Dispose();
 app.Context.Items.Remove("ObjectScopeProvider");

0
Dimitar Kapitanov
Telerik team
answered on 29 Jan 2009, 06:19 AM
Hello Hessner,
It is better to do so, as I was unable to verify whether the Items contents are to be disposed in the proper manner. Regarding the code my suggestion is to first remove, then dispose the scope instance, just in case.

Kind regards,
Dimitar Kapitanov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Development (API, general questions)
Asked by
Hessner
Top achievements
Rank 2
Answers by
Dimitar Kapitanov
Telerik team
Hessner
Top achievements
Rank 2
Share this question
or