This project has moved and is read-only. For the latest updates, please go here.

1.11 Constructing TwitterContext with ITwitterExecute

Jul 15, 2009 at 3:11 PM


I come across using oAuth and trying to construct twitter context. Anybody able to provide me sample on how to construct with ITwitterExecute. It seem like I cannot find any example from demo.




Jul 15, 2009 at 6:30 PM

Hi Ervin,

The reason I added the constructor with ITwitterExecute was so that I could use dependency injection to mock the object for testing. Normally, you wouldn't ever use this constructor yourself.  If you look inside of the LinqToTwitterTests project, there is a file called TwitterContextText that has a field named m_twitterExecute of type ITwitterExecute.  Here's the on-line link:

If you look at MyTestInitialize, where I initialize the tests, you can see that I assign a mock to m_twitterExecute.

In the TwitterContext constructor, I automatically set TwitterExecutor, which is ITwitterExecute, to a new instance of TwitterExecute, which is ITwitterExecute, if there is not an instance of ITwitterExecute passed in (i.e. the parameter is null).

When using LINQ to Twitter, you can instantiate the constructor as shown in the Program.cs example's in Main.  


Jul 16, 2009 at 5:11 AM

Hi Joe,

I will have a try on changeset version of 56275. Currently I am working on ASP.NET MVC with OAuth, I found the previous version is very convenient by just injecting IOAuthTwitter into TwitterContext's constructor. Unfortunately it is no longer exist in latest change set. I tried WebOAuthAuthorization, but it is only workable in web form.

Noticed that in version, TwitterContext is not auto inject twiter executor.


Jul 16, 2009 at 2:56 PM


I'd be happy to fix WebOAuthAuthorization for ASP.NET MVC, but I wonder if you can elaborate on why you say it's only workable in web forms?  Until I write an MVC sample I won't know first hand, so you might be able to give me a head start.

The only non-MVC'ish thing I can see WebOAuthAuthorization doing is it does a Response.Redirect.  While MVC likes to return an ActionResult that redirects instead, and I can fix that, to my knowledge that doesn't break anything in MVC.  So is there something else?

Jul 16, 2009 at 3:26 PM


That would be nice. Yes MVC's only problem with your mentioned above. I am happily to test it after you fix it. :)

Jul 16, 2009 at 3:59 PM

Done.  Check out the latest changeset and use MvcOAuthAuthorization.

How's that for response time? :)


(btw, response time might plummet because I'm heading out on a three day trip.)

Jul 17, 2009 at 5:14 AM


I am able to plug in MvcOAuthAuthorization perfectly in mvc. Do let me know if you need the demo project file.


Jul 17, 2009 at 2:16 PM


Oct 2, 2009 at 3:28 PM

Is there an MVC demo project file anywhere... or included in the latest release?