ProxyApi: Now With Intellisense!

After announcing ProxyApi in my last post I had a few people suggest that it would be more useful if it included some kind of intellisense.

So…now it does! Install the new ProxyApi.Intellisense NuGet package and you will automatically have intellisense for the generated JavaScript API objects.

I’ve made this into a separate package for 2 reasons:

  1. The original ProxyApi package still works perfectly on it’s own; and
  2. The intellisense implementation is a little but more intrusive than I would have liked

It works by adding a T4 template to the Scripts directory of your project that uses the ProxyApi classes to generate a temporary version of the script at design-time. That scripts is then added to _references.js so it gets referenced for any JavaScript file in the solution.

This would be fine, but unfortunately Visual Studio doesn’t have any mechanism for regenerating the T4 template automatically, meaning that changes to the API or MVC controllers wouldn’t be reflected until you either manually rebuilt the templates or restarted VS. For the time being I have worked around this used a simple Powershell script to re-evaluate all T4 templates after each build, but hopefully I can find a more elegant solution later.

Because this does add a slight performance penalty, and because not everyone would need intellisense support, I’ve left this as an extra package. If you prefer the vanilla ProxyApi then you can grab it here.

The next step will be generating TypeScript files using a similar mechanism, which would allow the intellisense to extend to the parameter types as well.

Watch this space…

Advertisements

7 thoughts on “ProxyApi: Now With Intellisense!

  1. Any chance you can put together a sample VS project, so I can see how you use it ? Just adding or @Script.Render(“~/api/proxies”) doesn’t do a lot after installing the nuget package…

    Did I mis-understand your instructions ?

    Thanks for any help you can give.

  2. Great Work but
    when building project (asp.net web api 2), it fires an error
    Running transformation: System.IO.FileNotFoundException: Could not load file or assembly ‘System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.
    File name: ‘System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’
    at ProxyApi.Reflection.ControllerElementsProvider.IsControllerType(Type type)
    at System.Linq.Enumerable.c__DisplayClassf`1.b__e(TSource x)
    at System.Linq.Enumerable.c__DisplayClassf`1.b__e(TSource x)
    at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
    at ProxyApi.ProxyGenerator.GenerateProxyScript()
    at Microsoft.VisualStudio.TextTemplating6A51537BC8E857274E2ACC1DC9A85AF079A0BEA59FB39D6D854FEC5C83FB6C0B29B7F900AE5F91111534E20029FD9362C3BB7781F9A75BAC4FAADBECAF5C6E54.GeneratedTextTransformation.TransformText() in d:\Projects\Server\Modules\Emeint.Server\Emeint.Server.Vendors\Scripts\proxyapi.intellisense.tt:line 28

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s