Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x.BuildInstancesOf<INHFactory>()
- .AddInstances(z => z
- .OfConcreteType<NHFactory>()
- .WithName("JCDC")
- )
- .CacheBy(InstanceScope.Singleton);
- using System.Reflection;
- using JCDCHelper.Logging.Interfaces;
- using JCDCHelper.NhAccess.Interfaces;
- using JCDCHelper.NhAccess.BusinessObjects;
- using JCDCHelper.Persistence.BusinessObjects;
- using JCDCHelper.Persistence.Interfaces;
- using POCAdmin3G.DAL.Interfaces;
- using POCAdmin3G.Jcdc.EO;
- using POCAdmin3G.Jcdc.Map;
- using StructureMap;
- using StructureMap.Attributes;
- namespace _Test_DAL
- {
- public class _BootstrapStuctureMap
- {
- private static bool _hasStarted;
- /// <summary>
- /// Bootstraps the structure map.
- /// Set up IOC for all parts of application
- /// Set up NHFactory for each DB with scope of one per application.
- /// Set up NHSession for Tran and NoTran. Give it a scope of HttpRequest or Thread
- /// </summary>
- /// <Author>fink.pete</Author>
- /// <CreateDate>8/31/2010</CreateDate>
- public void BootstrapStructureMap()
- {
- _hasStarted = true;
- ObjectFactory.Initialize(x =>
- {
- x.PullConfigurationFromAppConfig = false;
- x.Scan(y =>
- {
- y.Assembly(Assembly.GetAssembly(typeof(IPOCContrCtrlDAL))); // TestDisplay DAL
- y.Assembly(Assembly.GetAssembly(typeof(IWebAccess))); // JCDCHelper Persistance
- y.Assembly(Assembly.GetAssembly(typeof(INHSession))); // JCDCHelper NhAccess
- y.Assembly(Assembly.GetAssembly(typeof(INetLog))); // JCDCHelper Logging
- y.WithDefaultConventions();
- }
- );
- // needed for new one WebAccess per application
- x.BuildInstancesOf<IWebAccess>()
- .TheDefaultIsConcreteType<WinFormAccess>()
- .CacheBy(InstanceScope.Hybrid);
- // needed for new one Factory for JCDC per application
- x.BuildInstancesOf<INHFactory>()
- .AddInstances(z => z
- .OfConcreteType<NHFactory>()
- .WithName("JCDC")
- )
- .CacheBy(InstanceScope.Singleton);
- // needed for NHSession for JCDC HasTran per HttpRequest
- x.ForRequestedType<INHSession>()
- .AddInstances(z => z
- .OfConcreteType<NHSession>()
- .WithName("JCDC_HasTrans")
- .SetProperty(y => y.DBNameAndHasTran = "JCDC_HasTrans")
- )
- .AddInstances(z => z
- .OfConcreteType<NHSession>()
- .WithName("JCDC_HasNoTrans")
- .SetProperty(y => y.DBNameAndHasTran = "JCDC_HasNoTrans")
- )
- .CacheBy(InstanceScope.Hybrid);
- });
- //Debug.WriteLine(ObjectFactory.WhatDoIHave());
- //ObjectFactory.AssertConfigurationIsValid();
- // Set up the NhibernateFactories
- INHFactory jcdcFactory = ObjectFactory.GetNamedInstance<INHFactory>("JCDC");
- jcdcFactory.BuildFactoryByConfigFile<AcademicEO, AcademicEOMap>("~/JcdcDb.config");
- }
- /// <summary>
- /// Restarts StructureMap. Reset to original defaults.
- /// </summary>
- /// <Author>fink.pete</Author>
- /// <CreateDate>8/31/2010</CreateDate>
- public static void Restart()
- {
- if (_hasStarted)
- {
- ObjectFactory.ResetDefaults();
- }
- else
- {
- Bootstrap();
- _hasStarted = true;
- }
- }
- public static void Bootstrap()
- {
- new _BootstrapStuctureMap().BootstrapStructureMap();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement