Skip to content

Instantly share code, notes, and snippets.

@ielcoro
Created May 28, 2013 07:27
Show Gist options
  • Save ielcoro/5661058 to your computer and use it in GitHub Desktop.
Save ielcoro/5661058 to your computer and use it in GitHub Desktop.
Unity 3 Mapping Examples
public static void Configure(UnityContainer container)
{
//Mix explicit mapping with Auto-Registration
container.RegisterType<IEntityFrameworkUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager(), new InjectionConstructor());
//Select only repositories in loaded assemblies
container.RegisterTypes(AllClasses.FromLoadedAssemblies()
.Where(type => type.BaseType != null && type.BaseType.IsGenericType &&
type.BaseType.GetGenericTypeDefinition() == typeof(BaseRepository<>)),
WithMappings.FromMatchingInterface,
WithName.Default);
}
public static void Configure(UnityContainer container)
{
container.RegisterType<IEntityFrameworkUnitOfWork, UnitOfWork>(new HierarchicalLifetimeManager(), new InjectionConstructor());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment