Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 498109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:50:46+00:00 2026-05-13T05:50:46+00:00

I’m familiar with the standard repository, which has an interface resembling: public interface IRepository<T>

  • 0

I’m familiar with the standard repository, which has an interface resembling:

public interface IRepository<T>
    {

         IEnumerable<T> All();

         T GetByID(int id);

         //etc...

    }

My problem involves attempting to implement this pattern within Silverlight which restricts remote data access to async calls (which effectively removes the concept of a return value from the interface’s methods) How would one go about creating an IAsyncRepository and how would databinding to a control’s ItemSource occur after a returned call?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:50:46+00:00Added an answer on May 13, 2026 at 5:50 am

    If you want to use a repository pattern with Silverlight, I think the best approach is to pass in a callback method of some sort to every method, which is then called by the repository when the async call finishes. You can pass the returned object in the callback function, which is when you can setup the data-binding.

    The code below is an example of how this works. It’s not using the standard repository pattern, but I think you can see how it could be modified appropriately:

        public void CreatedNamedRoom(string ownerUserId, string roomName, Action<Exception, Room> callback)
        {
            notificationClient.CreateNamedRoomAsync(ownerUserId, roomName, callback));
        }
    
        void notificationClient_CreateNamedRoomCompleted(object sender, CreateNamedRoomCompletedEventArgs e)
        {
            var callback = e.UserState as Action<Exception, Room>;
            if (callback != null)
            {
                callback(e.Error, e.Result);
            }
        }
    

    And then you use it something like this:

        roomData.CreatedNamedRoom(userId, roomName, (error1, room) =>
        {
            if (error1 == null)
            {
                // Setup your databinding here...
                this.Room = room;
            }
        });
    

    Effectively, the repository becomes a wrapper for the annoying event-driven async WCF proxy methods that MS makes you use. I generally find callbacks to be a lot easier to work with than events, since you don’t always know what triggered the event, and maintaining the state appropriately is a PITA. But if you wrap the events with a layer that you can use with callbacks (the Action<> bit above), maintaining the appropriate state is a lot easier.

    I should also note that generic repositories probably aren’t going to work well with Silverlight, assuming that you’re using something like WCF on the back-end, since SOAP et al don’t support generics very well. A better approach is to use the repository as an infrastructure contract, as described here. It’s better architecturally, and it works better with Silverlight/WCF.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.