thedersen/UnityConfiguration — Issue #6: AssemblyScanner not bin folder friendly for web apps
Author: chrisnelsoncentare
Created: 2011-12-09 16:22:27+00:00
State: open

I tried to incorporate the UnityConifguration library in a MVC3 project, and was getting errors that my mappings weren't found. I used the following code, which is very similar to what I use from StructureMap.

```javascript
Scan(scan =>
{
scan.AssembliesInBaseDirectory();
scan.WithNamingConvention();
});
```

When running the app, the Unity container object didn't have any registrations. After digging into it, and only by comparing StructureMap's source for their AssembliesFromApplicationBaseDirectory() method, I discovered you are only looking in the AppDomain.CurrentDomain.BaseDirectory directory (which is great for desktop apps), but does no good for web apps. The missing piece is additionally looking in AppDomain.CurrentDomain.SetupInformation.PrivateBinPath which is where the assemblies are for web apps.

The work-around is to do the following:

```javascript
Scan(scan =>
{
scan.AssembliesInDirectory(AppDomain.CurrentDomain.SetupInformation.PrivateBinPath);
scan.WithNamingConvention();
});
```

I'm sure others have run into this and it might be nice to bake this into the UnityConfiguration.AssemblyScanner class.