Unit of Work and Entity Framework

The Unit of Work pattern is a really useful pattern that I really haven’t given a lot of thought to for some reason. Generally it just seems to need very little attention. I guess frameworks around us shield us from it… But I guess it the more you learn, the more you think of, and the more time you spend working on things that you previously never invested much thought in.

Anyhow, recently, working with Entity Framework (yes…it is another EF post…) I realized that this pattern is really key to a lot of things, and it isn’t always that easy to implement. So I decided to Google it and borrow heavily from some smarter person than me who had already built a nice solution for it. Unfortunately, all the information I found regarding UoW and EF was overly simplified, and generally based around abstracting away EF in a single repository.

More...

Emancipating your Entity Framework entities

Ok, so first of all, it has been a VERY long and VERY quite period on my blog. I guess that is just the way it is, sometimes life just takes up too much time to be able to blog to the extent I want to. On the other hand, I have been very busy with some cool projects, including some cool technologies, so it is all good I guess.

Now back from the dead I hope that my blogging will pick up, and this is the first in a series of blog posts about things I have figured out during my silent months. I know that Entity Framework is far from what I normally blog about, but it is still something I use, and something I spent some times getting my head around. Understanding EF as such isn’t that hard, the hard part was getting it to work in a fashion that suited me, and one of the things I don’t like is just adding a gazillion repositories on top of EF and be done with it. And I don’t like stepping 15 levels into my objects, lazy loading things as I go along. And I want things to be as DRY as possible. So I prefer having more “emancipated” objects. I want my objects to have freedom to do what they need to do. This makes the programming so much simpler and easier to follow… But it also requires some features like DI… And on top of that, being a bit paranoid, I prefer abstracting away my ORM as much as possible…

So this post is about how I have decided to use EF in my current projects, and I would love any feedback you got…

More...

WP7 Database Support – The Quick and Dirty Intro

I finally got my act together and started doing some WP7 development again. It has been a while, and a few things have happened since I was last doing it…Mango for example. This also means that there are a heap of new features available to me as a developer, but the one that I have got real excited about is actually the database support…

So, Chris, being who you are, why in the world did you chose that feature to get excited about? Well, partly because it was the first new feature I have tried out. But mostly because I sort of didn’t expect to be as neat. Knowing that it was based on SqlCE, I sort of expected it to use a subset of ADO.NET, and regular SQL for access. However, color me surprised when I realized that that wasn’t the case. Instead, it uses Linq-to-SQL and attribute based entity mapping. And on top of that, I didn’t have to create a base database and include it in my project in some obscure way. The database can be created based on the attributes, which is a nice little treat…

More...

Code from my testing presentation

Last week, I had the honor of having been invited to present my thoughts on testing at a IT consultant agency here in Stockholm. And even if I looked forward to it, and felt privileged to be allowed to share my view with these other devs, I still felt a bit hesitant. I was still going to step in front of a bunch of devs and present a somewhat less glorifying view on testing than you normally get. Not that I am all against testing, definitely not, but I do have a somewhat looser view on what, when and how to test software than say for example you regular TDD guy…

Walking in to the presentation, I had material for about an hour of presenting, and hoped to maybe extend it to an hour and a half with discussions and debate (I did hope for a lot of discussion as it was really the goal of my presentation). However, it turned out that after an hour and a half, we had a break for food, and then I kept going a bit more. I think we ended the session after almost 3 hours, even though I think it could probably been longer if I had pushed my points a bit more to the extreme than I did.

More...

Securing a NancyFx module with the Azure Access Control Service

In my previous post I gave a semi-quick introduction to NancyFx. This time, I want to take Nancy and combine it with Azure ACS. Not a very complicated thing as such, but still something I want to do as I enjoy working with both technologies.

Just as in the last post, I will self-host Nancy in a console application, and use NuGet to get it going. I will also re-use the “www.nancytesting.org” domain I set up in my hosts file in the last post.

Once I got my console application going with a host, and an empty NancyModule, it is time to start looking at the ACS.

More...

Trying Out NancyFx

As part of not doing very much coding lately, I have decided that I am going to try to spend more time trying out new frameworks and technologies. And hopefully, that will en up with a lot more blog posts with interesting stuff. This time I have looked at a ridiculously funky micro framework for building HTTP-based services called NancyFx. It is really simple to get started with, but still very powerful…and modern…

Nancy can be hosted in a variety of ways, including in ASP.NET MVC, WCF and self-hosting. In this post, I will look at hosting Nancy in a console application as I had little interest in setting up anything big. And using NuGet, it was a piece of cake to get started. Just start up a new Console application project and then NuGet Nancy.Hosting.Self.

More...

Sample code from my LEAP presentation about cross-framework code sharing

Yesterday I was invited to speak in front of a bunch of really sharp guys attending the Lead Enterprise Architecture Program, LEAP, at Microsoft here in Stockholm. The topic of the day was how to share code between projects targeting multiple frameworks/platforms. Basically “how can we share code between projects aimed at WP7, Windows 8, Silverlight and WPF” in a useful way, limiting the duplication of code as well as maintenance.

Most of my presentation revolved around a sample I had written to target all platforms. It is a very simple application, but still shows that it is very possible to get it to work.

More...

A Rant About Unit Testing and Stuff

I think it is time for another rant. Actually I really don’t, as my blog is supposed to be about coding, not about me ranting… It seems like my blog has slowly gone from code centric posts, to ramblings of a grumpy Microsoft developer. Sorry about that, and I promise to focus more on code in the future…

Lately I have travelled around and talked at a bunch of conferences, and heard a lot of really smart people talk about a lot of really cool things. This got me thinking a bit about my own way of dealing with new technology, as well as about my own way of doing things today… The result of this thinking is that I am going to try and make 2 changes. First, I am going to try and get out and about and try more new stuff. More frameworks, technologies and maybe even more languages… Hopefully this will fuel my blog with more code related posts as well as interesting revelations and thoughts. Secondly, I might have revisit my stance on unit testing and TDD…

More...

Another good conference at an end

So, here I am sitting at the speakers lounge at DevConnections at the MGM Grand in Las Vegas after another great conference. It is amazing the level American conferences keep. The speakers are great, the conferences are well organized and everything just flows. And it is pretty cool to be able to share the speakers lounge with people like John Papa, Dan Wahlin, Paul Litvin, Juval Löwy and Scott Hanselman. It is also very humbling. These presenters are really the cream of the crop, and I am still kind of wondering what I did here. But I got to do it, and had a lot of fun, so I won’t complain.

More...