Posibilities of using ASP.Net Web API with Prism

Topics: Prism v4 - WPF 4
Oct 16, 2012 at 4:02 PM


I am a beginner for both Prism and Web API. And interested in both. I want to know that is it possible to use both of them together.

If possible, please give me some samples.


Oct 16, 2012 at 6:34 PM


I don't have any experience using Web API, but in my opinion, as a WPF application can consume a Web API HTTP Service you should be able to use it also in a WPF Prism application.

As far as I know, the only differences you should take into account when using it in a Prism application, compared to a pure WPF application, are where to initialize the HttpClient used to reach the service and how to consume it in different modules while maintaining a loosely coupled pattern.

Based on my understanding, I believe you could initialize the HttpClient in the main project (for example in the bootstrapper) and in case you want to consume it in different modules, you could wrap it in a shared service that could be used by the different parts of your application to reach the HTTP Service. Then, you could also register the aforementioned shared service in the dependency injection container of your application, so that it could be later injected (for example, when using constructor injection or property injection) in the views, view models, etc, of any module.

So far, I am unaware of the existence of a sample that portrays a Prism application consuming Web API HTTP Services. However, as a starting point, I believe you could find the following ASP.NET Hands on Lab useful as it details how to create a basic WPF application that interacts with a HTTP Service:

I hope you find this useful,

Damian Cherubini

Oct 17, 2012 at 6:08 PM

Hi Damian,

Thank you for your valued feedback!

Oct 18, 2012 at 6:44 AM

. . . And, Is that all?

No any response from the developers of Prism?

I need the support from the Prism developers.

Waiting for your reply...

Oct 18, 2012 at 3:51 PM


Based on my understanding, as Damian mentioned Prism should not introduce any difference from the approach mentioned in this article

In Prism, you can create and set a new instance of your HttpClient, and make further calls in your applications without problems. This approach could be implemented in any part of your application.

The only difference you may find when using Prism, is that in case you want to share the same HttpClient instance, in order to consume it in a loosely coupled component, you may have to implement the logic to pass this instance, for example by benefiting of dependency injection containers or shared services as mentioned above.

Please, let us know if you have any issues when following this approach.


Agustin Adami

Oct 18, 2012 at 7:48 PM

Hi Adami,

I got the Web API part. Its Ok now. Then I will try the Prism part.

Thank You!