Taylohtio/GeneralSSO/GeneralSSO.Server/CodeFiles/Infrastructure/IoC/IoCConfiguration.cs

72 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.ServiceLocation;
using NHibernate;
using NHibernate.Cfg;
using StructureMap;
using StructureMap.Attributes;
using StructureMap.ServiceLocatorAdapter;
using Taloyhtio.GeneralSSO.Server.CodeFiles.Infrastructure.DataAccess;
using Taloyhtio.GeneralSSO.Server.CodeFiles.Infrastructure.DataAccess.Impl;
using Taloyhtio.GeneralSSO.Server.CodeFiles.Repositories;
using Taloyhtio.GeneralSSO.Server.CodeFiles.Repositories.Impl;
using Taloyhtio.GeneralSSO.Server.CodeFiles.Services;
using Taloyhtio.GeneralSSO.Server.CodeFiles.Services.Impl;
namespace GeneralApi.Core.Infrastructure.IoC
{
public class IoCConfiguration
{
public static void Configure()
{
ObjectFactory.Configure(
x =>
{
x.ForRequestedType<ILogRepository>()
.TheDefaultIsConcreteType<LogRepository>();
x.ForRequestedType<ILogger>()
.TheDefaultIsConcreteType<Logger>()
.AsSingletons();
x.ForRequestedType<Configuration>().AsSingletons()
.TheDefault.Is.ConstructedBy(ctx => NHConfiguration.Configure());
x.ForRequestedType<ISessionFactory>().AsSingletons()
.TheDefault.Is.ConstructedBy(ctx => ctx.GetInstance<Configuration>().BuildSessionFactory());
// x.ForRequestedType<ISession>().AsSingletons()
// .TheDefault.Is.ConstructedBy(ctx => ctx.GetInstance<ISessionFactory>().OpenSession());
x.ForRequestedType<ISessionSource>()
.TheDefaultIsConcreteType<SessionSource>()
.AsSingletons();
// x.ForRequestedType<IUnitOfWork>()
// .TheDefaultIsConcreteType<UnitOfWork>()
// .CacheBy(InstanceScope.Hybrid);
x.ForRequestedType<IClientAuthorizationRepository>()
.TheDefaultIsConcreteType<ClientAuthorizationRepository>();
x.ForRequestedType<IClientRepository>()
.TheDefaultIsConcreteType<ClientRepository>();
x.ForRequestedType<INonceRepository>()
.TheDefaultIsConcreteType<NonceRepository>();
x.ForRequestedType<ISymmetricCryptoKeyRepository>()
.TheDefaultIsConcreteType<SymmetricCryptoKeyRepository>();
x.ForRequestedType<IRolesProvider>()
.TheDefaultIsConcreteType<RolesProvider>();
});
var locator = new StructureMapServiceLocator(ObjectFactory.Container);
ServiceLocator.SetLocatorProvider(() => locator);
}
}
}