2012-12-21

Asp.net MVC MEF: Per Request Lifetime

,
Like the title says, i want to use MEF in an Asp.Net MVC application and the lifetime of the object has to be exactly the same as the lifetime of the request. In short, i want 1 single unique object that is recreated per request. In MEF there is a way to control the lifetime of the created object. This is specified the PartCreationPolicy attribute that you can use to decorate the object. In my test project i installed the nuget package i created in this post to incorporate MEF in an Asp.net MVC application. I also created an object called MyCustomObject...
Read more →

2012-12-16

Asp.net MVC: reuse Areas from external project

,
I created a MVC project that has an Area defined that i would like to use in an other MVC project. Here is the structure. I created a reference between the AlphaArea and MainApp project. When i run the application is see that the area registration of the AlphaArea is executed. But when i try to go to the area i get an error. What this error says, is that the view for the Index of the AlphaController in the Alpha area isn’t found. This makes perfect sense because the Index view isn’t declared in the MainApp project and this is where MVC  tries to...
Read more →

2012-12-12

Web Api: Passing a Complex type in JSON

,
In one project i wanted to pass a complex type to the Post method of an Web Api controller. The Post itself will be done using JQuery in the JSON format. I noticed that the parameter was always null. After a bit of searching i found the solution. The Set Up Server side public class ValuesController : ApiController { // POST api/values public void Post(MyComplexType value) { } } public class MyComplexType { public string Name { get; set; } public MyComplexSubType MyComplexSubType { get; set; } ...
Read more →

2012-12-07

WebApi: File upload and download using JQuery and submit button

,
I am going to create a WebApi service called FileService that can be used to upload and download files. The service will only contain 2 methods. A Post to upload and a Get method that accepts an id parameter to identify the file that needs to be downloaded. Let’s start with the Post method. The Post method This method will look in the Request object to see if there are any posted files. If so, it will loop over the files and create them on the server side. The server will return a 201 HttpStatus and a list of strings that will contain the full path of the...
Read more →

2012-12-01

Paged Grid with Knockout.js and WebApi

,
I want to see how easily you can create a custom grid that uses an WebApi as datasource and that allows the user to page the data and also allow them to choose a page size for the grid. The WebApi The WebApi will return a viewmodel that contains an array of names (string) and a property that specifies how many pages that there are available. public class NamesGridViewModel { public IEnumerable<String> Names { get; set; } public int NumberOfPages { get; set; } } The WebApi itself will contain a method that accepts 2...
Read more →

2012-11-28

Nuget package: integrated MEF in Asp.Net MVC 4 and WebApi

,
Today i wanted to create my first Nuget package and i already knew what i would publish to the world. I wanted to make the code that is used to use MEF in Asp.Net MVC 4 and the WebApi (view this post) easy to reuse in other projects. I rewrote the code in a class libary. After a little google-ing i found a video that explained how to create a Nuget package using the Nuget Package Explorer.  After that i created a user at the Nuget gallery so i got my API Key. With this, i had all the information i needed to published my first Nuget package and i have a feeling that it will not be my last...
Read more →

2012-08-31

MEF in Asp.Net MVC 4 and WebApi

,
MEF stands for “Microsoft Extensibility Framework”. If you want an overview of MEF, you can look here. In this post we will integrated MEF with Asp.Net MVC 4 and with the WebApi. Asp.Net MVC 4 First of all you need to reference the “System.ComponentModel.Composition.dll” assembly which contains the implementation of MEF. Now where are going to create a MEF controller factory. Like the name says, it will be responsible to create the controller that is requested. public class MefControllerFactory : DefaultControllerFactory { private readonly CompositionContainer _compositionContainer; ...
Read more →

2012-08-14

Entity Framework: Database Migrations

,
If you don’t like writing SQL DDL statement, like me, than Entity Framework is very handy. With the Code-First, you can write your model and don’t need to worry about your database. It is generated for you by Entity Framework. This is very handy but what if you are working with an existing database? Or if you need to support different versions of your database? That is where database migrations come in to play. Before we start Create an Asp.Net MVC 4 application Use Nuget to install the latest version of the Entity Framework (5.0.0-rc) Because i am not...
Read more →