Created
December 3, 2012 03:02
-
-
Save bradoyler/4192338 to your computer and use it in GitHub Desktop.
IoC container for RavenDB within MemFlex project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Configuration; | |
using System.Linq; | |
using System.Web.Mvc; | |
using FlexProviders.Aspnet; | |
using FlexProviders.Membership; | |
using FlexProviders.Raven; | |
using FlexProviders.Roles; | |
using LogMeIn.Models; | |
using Raven.Client; | |
using Raven.Client.Document; | |
using StructureMap; | |
namespace LogMeIn | |
{ | |
public static class IoC | |
{ | |
public static IContainer Initialize() | |
{ | |
ObjectFactory.Initialize(x => | |
{ | |
x.Scan(scan => | |
{ | |
scan.TheCallingAssembly(); | |
scan.WithDefaultConventions(); | |
}); | |
x.For<IFilterProvider>().Use<SmFilterProvider>(); | |
x.For<IFlexMembershipProvider>().HttpContextScoped().Use<FlexMembershipProvider>(); | |
x.For<IFlexRoleProvider>().HttpContextScoped().Use<FlexRoleProvider>(); | |
x.For<IFlexUserStore>().HttpContextScoped().Use<FlexMembershipUserStore<User, Role>>(); | |
x.For<IFlexRoleStore>().HttpContextScoped().Use<FlexMembershipUserStore<User, Role>>(); | |
x.SetAllProperties(p => p.OfType<IFlexRoleProvider>()); | |
x.Forward<IFlexMembershipProvider, IFlexOAuthProvider>(); | |
x.For<IApplicationEnvironment>().Singleton().Use<AspnetEnvironment>(); | |
x.For<ISecurityEncoder>().Singleton().Use<DefaultSecurityEncoder>(); | |
x.ForSingletonOf<IDocumentStore>().Use(() => { | |
var documentStore = new DocumentStore(); | |
documentStore.ConnectionStringName = "Raven"; | |
documentStore.Initialize(); | |
return documentStore; | |
}); | |
x.For<IDocumentSession>().HybridHttpOrThreadLocalScoped().Use(ctx => | |
{ | |
return ctx.GetInstance<IDocumentStore>().OpenSession(); | |
}); | |
}); | |
return ObjectFactory.Container; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment