Implementing Context factory for Telerik OpenAccess ORM

Thread is closed for posting
6 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 07 Aug 2009 Link to this post

    Requirements

    RadControls version

    2009 Q2
    Telerik OpenAccess ORM version 2010.1.414.3
    .NET version

    3.5 SP1
    Visual Studio version

    2008
    programming language

    C#
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION

    This is an example of how  a so called 'context factory' is implemented. The .zip file contains 3 projects:

    1) Model (Data Model)
    2) Repository (BLL)
    3) Website (UI)

    It uses the Northwind database on a SQL2005 server.
    The basic idea is to have a few repositories for each 'set of entities'. So for example an 'OrderRepository' contains functionality to get 'Orders' from the database, but also the 'OrderDetails'.

    The only thing that is needed to get a repository together with an active scope (that is based per Http Session) is to call this:

    1 ArticleRepository repArticle = ContextFactory.Get<ArticleRepository>(Session.SessionID); 

    So then the ContextFactory is asking the RepositoryFactory to return a repository of the type 'ArticleRepository' using the 'active scope' for a particular session.


    UPDATE:The most recent version of this project can be found in the Software Development Kit, which you can download here. In case you have questions related to this project, please use the support ticketing system.
  2. Gary
    Gary avatar
    5 posts
    Member since:
    Apr 2008

    Posted 15 Aug 2009 Link to this post

    Hi,

    I have implemented something like the repository factory on a per Http request basis.
    What is the advantage of having the repositories persist for a session?

    The example stores the dictionary as a static variable, why is it not stored as a session variable.
    Am I missing something simple here?

    Thanks
    Gary
  3. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 20 Aug 2009 Link to this post

    Hi Gary,

    The advantage of this approach is that every user that visits the web site gets to work with his/her own object scope, hence his/her own repository. The scope should not be shared by multiple users/sessions because it is not synchronized by itself. On the other hand, all object scope that will enter the dictionary(as in the implementation we discuss) will share the 2nd level cache. So from the perspective of using cached objects, the data access will still be optimized.

    Greetings,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  4. CodeMonkey
    CodeMonkey avatar
    10 posts
    Member since:
    Oct 2009

    Posted 31 Oct 2009 Link to this post

    What about when the session finishes; how are the IObjectScopes removed from the ScopeFactory?

    [edit 1/11/09] In fact this design seems to be at odds to the best practices presented in http://www.telerik.com/support/kb/orm/general/best-practices-with-openaccess.aspx
  5. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 02 Nov 2009 Link to this post

    Hi CodeMonkey,

    Yes you are right, the scope should be disposed of when the Session ends as presented in the best practice KB article.

    Kind regards,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 13 Jun 2011 Link to this post


    The most recent version of this project can be found in the Software Development Kit, which you can download here. In case you have questions related to this project, please use the support ticketing system.

    All the best,
    Damyan Bogoev
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Back to Top