Tuesday, September 25, 2012

Func Injection in Unity

Let your container be your factory. :)

If you are using LinqToSql and dependency injection, then you have probably created a factory with which you create DataContexts. But what if you could just let your IOC Container do that work for you? You can!

If you are using Unity then you can inject a Func<T> of any registered type. Unity will automatically bind the injected Func to the container's resolve method, thus preserving the resource Lifetime Manager.

Example Code

public class FuncInjectionTests
    public void TransientLifetimeFuncIsThreadsafe()
        var container = new UnityContainer();
            .RegisterType<IUserService, UserService>(
                new ContainerControlledLifetimeManager())
            .RegisterType<IDataContext, DataContext>(
                new TransientLifetimeManager());
        var parallelOptions = new ParallelOptions {MaxDegreeOfParallelism = 100};
        Parallel.For(0, 1000, parallelOptions, i =>
            var userService = container.Resolve<IUserService>();
            Parallel.For(0, 1000, parallelOptions, j =>
        Assert.Equal(1, UserService.Count);
        Assert.Equal(1000000, DataContext.Count);
public interface IUserService
    void Update();
public interface IDataContext : IDisposable
    void UpdateUser();
public class UserService : IUserService
    public static int Count;
    private readonly Func<IDataContext> _dataContextFactory;
    public UserService(Func<IDataContext> dataContextFactory)
        _dataContextFactory = dataContextFactory;
        Interlocked.Increment(ref Count);
    public void Update()
        using (var dataContext = _dataContextFactory())
public class DataContext : IDataContext
    public static int Count;
    public DataContext()
        Interlocked.Increment(ref Count);
    public void UpdateUser()
        Trace.WriteLine(Thread.CurrentThread.ManagedThreadId + " - " + Count);
    public void Dispose()
Shout it


Saturday, September 15, 2012

The problem with the Nintendo eShop

Dear Nintendo,

I am a huge fan. I have owned every single Nintendo console that has ever been released (except for the Virtual Boy, naturally). You have made so many great games, and I love them all. I enjoy Mario, Zelda, Metroid, Donkey Kong, pretty much all of your franchises.

So, why won't you let me buy these games from you again?

The Nintendo 3DS eShop and the Ambassador Program

The eShop is Nintendo's online store and digital distribution system for the Nintendo 3DS. With it they sell small games, old emulated virtual console games, and they just recently selling complete feature titles via the eShop. It's a great idea that has been very successful, and it shows that Nintendo is trying to keep up with the times. Other companies, such as Valve and Apple, have made the vast majority of their profits in recent years by take percentages from their digital distribution services, Steam and iTunes respectively.

After the very sluggish start for 3DS sales, Nintendo inevitably had to commit to a price cut for their new hardware. To try and appease consumers who had already paid full price for their 3DS, Nintendo gifted early adopters with the "Ambassador Program". This granted all 3DS owners, whom had purchased their console prior to August 11th 2011, 20 free downloadable titles via the Nintendo eShop. These included 10 NES titles, and 10 GBA titles.

Nintendo has shown us that they can easily emulate software from previous consoles on the Nintendo 3DS.

The Current Predicament

Now that it is far too late to gain access to the Ambassador program, you can no longer download many of the virtual titles that were offered. Not even by PAYING for them! Not only are they completely unavailable now, but Nintendo has stated that they "currently have no plans to release those titles again."

When I look at the eShop's very small and weak game lineup, I find myself feeling very frustrated. Nintendo has so many classic games that I would love to pay for again and play again, and yet they refuse to release them to customers.

Nintendo is refusing to sell us software that they have already released; and they wonder why they are losing money for the first time in their company's history?

Nintendo eShop by the Numbers

Nintendo has been criticized for their handling both their Wii and DS eShops poorly, and I feel that this is rightly so. They do not have consistent new releases, they do a poor job of announcing and scheduling their releases, and worst of all they offer a very limited number of available titles.

  • Number of NES Games: 707
  • Number of GameBoy Games: 528
  • Number of GBC Games: 549
  • Number of SNES Games: 786
  • Number of GBA Games: 1017
  • Number of eShop Virtual Console Games: 68

Being that Nintendo owns the rights to their own games, and that they have already build the infrastructure to support selling and distributing these games on a global scale, I find these numbers to be embarrassing! Nintendo has already done all of the heavy lifting, why not put that system to better use?

A good analogy would be that Nintendo has build a transcontinental rail road system across the United States, but is only running a dozen trains on it.

Arguments Against Selling More Games

As I understand it, there are only three arguments against loading up a service like the eShop with an arsenal of downloadable titles:

  1. Oversaturation
    - By releasing too many games on the virtual console you could obscure smaller titles and reduce their sales.
    + I fail to see this as a problem, for as long as people are buy these old games (that would otherwise not be selling at all) you are still making money where you would have been before.
    + Additionally, there are over 1500 games available on Steam, and I have not seen Valve complain about that.
  2. Cross Promotional Releases
    - When a new game in a series is about to come out, there is often a sales spike for the previous games. This is partly because of the promotional advertise of the new game, but also because games often want to go back brush on the old games to prepare for next title, as well as some people just literally can not wait to play the game again.
    + Make some sales is always advantageous over making no sales, and sales, discounts, or bundles can work to help bolster sales prior to a game launch.
    + Again we can look to Steam for an example of how to make this work. Value uses every trick in the book to help promote new game sales, and it works out very well for them.
  3. Maintenance
    - The more games you release, the more games you have to provide support for.
    + Consoles are a controlled environment, there are not going to be issues with driver versions or third party software. All Nintendo has to do is support their emulators, which should (for the most part) be a one size fits all product. I can not see the cost in maintenance for this being overwhelming.
    + If open source software projects can do it in their spare time after work, then you Nintendo can too.

Summary: Nintendo should put more games on the Virtual Console.

So please, shut up and take my money,

Real Time Web Analytics