Autofac is a very popular dependency injection framework. This content will likely include C# code examples showing usage of Autofac for managing dependencies.

Xamarin Forms – Jumpstart Your App With Autofac

I love dependency injection frameworks ever since I started using them. Specifically, I'm obsessed with using Autofac and I have a hard time developing applications unless I can use a solid DI framework like Autofac! I've recently been working with Xamarin and found that I wanted to use dependency injection, but some of the framework doesn't support this well out of the box. I' was adamant to get something going though, so I wanted to show you my way to make this work. Disclaimer: In its current state, this is certainly a bit of a hack. I'll explain why I've taken this approach though! In your Android projects for Xamarin, any class that inherits from Activity is responsible for being created by the framework. This means where we'd usually have the luxury of passing in dependencies via a constructor and…

2 Comments

Unity3D And How to Master Stitching Using Autofac

In Unity3D, the scripts we write and attach to GameObjects inherit from a base class called MonoBehaviour (and yes, that says Behaviour with a U in it, not the American spelling like Behavior... Just a heads up). MonoBehaviour instances can be attached to GameObjects in code by calling the AddComponent method, which takes a type parameter or type argument, and returns the new instance of the attached MonoBehaviour that it creates. This API usage means that: We cannot attach existing instances of a MonoBehaviour to a GameObject Unity3D takes care of instantiating MonoBehaviours for us (thanks Unity!) ... We can't pass parameters into the constructor of a MonoBehaviour because Unity3D only handles parameterless constructors (boo Unity!) So what's the problem with that? It kind of goes against some design patterns I'm a big fan of, where you pass your object's…

1 Comment

Using Autofac With Unity3D

Why Consider Using Autofac With Unity3D? I think using a dependency injection framework is really valuable when you're building a complex application, and in my opinion, a game built in Unity is a great example of this. Using Autofac with Unity3D doesn't need to be a special case. I wrote a primer for using Autofac, and in it I discuss reasons why it's valuable and some of the reasons you'd consider switching to using a dependency container framework. Now it doesn't need to be Autofac, but I love the API and the usability, so that's my weapon of choice. Building a game can result in many complex systems working together. Not only that, if you intend to build many games it's a great opportunity to refactor code into different libraries for re-usability. If we're practicing writing good code using constructor…

2 Comments

ProjectXyz: Enforcing Interfaces (Part 2)

Enforcing Interfaces This is my second installment of the series related to my small side project that I started. I mentioned in the first post that one of the things I wanted to try out with this project is coding by interfaces. There's an article over at CodeProject that I once read (I'm struggling to dig it up now, arrrrrghh) that really gave me a different perspective about using interfaces when I program. Ever since then I've been a changed man. Seriously. The main message behind the article was along the lines of: Have your classes implement your interface, and to be certain nobody is going to come by and muck around with your class's API, make sure they can't knowingly make an instance of the class. One of the easiest ways to do this (and bear with me here, I'm…

2 Comments

End of content

No more pages to load