• .NET on Docker at Dot Net North

    I miss going to user groups, but with all the videos online now it is does mean I can get to more of the slightly further away user groups like Dot Net North. Even if I don't get to talk to anyone there.

    I first saw Docker being used by a developer in my co-working space for his Dating Site Whitelabel platform. The platform's userbase was growing and he was experimenting with different infrastructures to help support that growth. Docker enabled him to set up test environments that would be identical to the final production environment, to set them up quickly and repeatedly. He found this …

  • Forms Authentication in .NET Core (AKA Cookie Authentication)

    In .NET Core MVC you're encourages to use .NET Identity, but you don't have to. You can manage your own user identities and you use forms authentication which is now called Cookie Authentication (which is a better name really).

    You need to install the Microsoft.AspNetCore.Authentication.Cookies nuget package.

    There is some configuration that needs to go in startup.cs:

    public void ConfigureServices(IServiceCollection services)

    {

    services

    .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)

    .AddCookie(options => {

    options.AccessDeniedPath = "/ …

  • My Windows Services Panel

    Screenshot of My Windows Services Panel

    As a developer I have a lot of different types of Windows Services installed on my computer for the different projects I work on. Services like MS SQL Server Express, MS SQL Server, IIS, MSMQ and MySQL.

    I don't use all of them all of the time, but I would normally leave them running because I couldn't be bothered trawling through all of the services in Services Manager to stop and start them. Having them running all the time made my computer take longer to startup and I felt like it was slowing it down generally and stealing battery power.

    So I created My Windows Services Panel as a way to …

  • NHibernate Search String Dictionary Bridge

    NHibernate Search is an extension to NHibernate that uses Lucene to give you full text search using Lucene under the hood. It also makes using Lucene in your .NET app easier than using Lucene.NET directly.

    Lucene only indexes text on a document in a flat key-value structure. Bridges are used to turn properties on your indexed documents into text.

    NHibernate Search comes with bridges for common types such as enum, but you can also write your own. This is an example of a bridge that turns a Dictionary property on your indexed objects into a set of properties on the lucene document. It only …

  • Xamarin Forms at NDC London 2014

    If you're interested in finding out more about Xamarin Forms you may find the following interesting:

    Free eBook: Creating Mobile Apps with Xamarin.Forms by Charles Petzold (Preview edition)

    Video: Creating your first Xamarin.Forms App (Xamarin Evolve 2014)

    Video: Xamarin.Forms is Even Cooler Than You Think (Xamarin Evolve 2014)

    Video: XAML for Xamarin.Forms (Xamarin Evolve 2014)

    Video: Extending Xamarin.Forms with Custom Controls (Xamarin Evolve 2014)

  • Dizzy Dalek at NDC 2014

    The video of my talk on MonoGame and 3D (featuring a dizzy dalek) is now live on Vimeo:

    You can find the demo code on GitHub.

    Other NDC Game Development Related talks

    If you enjoyed this talk, you may also enjoy:

    Cross-platform physics-based gaming using MonoGame and Farseer

    Game and Simulator Physics for Developers, Gamers and Petrol Heads

    Porting Quake III to F#: A Journey to Functional Programming

  • Sharing your view model between Monogame and XAML

    If you create a new Monogame Windows Store XAML Project. You will get a XAML page called GamePage.xaml and you'll get the monogame game class Game1.cs. If you want display data from your game class in XAML or if you want to take input from XAML into your game then these two sides are going to need to communicate.

    One way they can communicate is by sharing a view model. As the XAML page creates the instance of your game class, it can also let your game class know about it's view model. Like this in GamePage.xaml.cs:

    public GamePage(string launchArguments)

    {

    this.InitializeComponent(); …

  • Real readonly lists in C#

    In C# there is the readonly keyword that enforced the rule that the variable must be initialised as it's declared or in the constructor. This works as expected for simple types, but for objects and lists it's not quite like that. With a list, you can still add, remove and change items in the list. You may also expose a list as a property with a public get and a private set. You want the owner class to be able to modify the list items, but you don't want anything outside the class to modify the list items.

    Here is an example with an almost readonly list, but as you can see it's not as readonly …

  • Mocking with NSubstitute

    My previous C# mocking framework of choice was MOQ. It's very powerful and fairly easy to use, but I recently started using NSubstitute and fell in love with how easy and intuitive it was to use.

    The cleverest part is that unlike MOQ the mocks produced actually implement the interface they're mocking and this makes the code much clearer and a little bit shorter.

    Here is a very simple example:

    var mockThing = Substitute.For<IThing>();

    mockThing.DoThingy().Returns("Something");

    // Use mock thing

    UseThing(mockThing);

    In MOQ this is also quite straightforward but the setup code to change …

  • Using extension methods to filter IQueryable data collections

    As I talked about in my post Do we need the repository pattern? I’ve been thinking about how we can make a testable data access layer with Entity Framework without using a repository pattern. I showed how you could do that in my post Mocking your Entity Framework data context and testing it in .NET MVC. However losing the repository also loses a nice centralised place to keep your query logic. In this post I’ll show you a nice simple way to use extension methods to do this.

    Suppose you’re using Entity Framework to store a collection of foos and there are several places in your app that you …