Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. x.BuildInstancesOf<INHFactory>()
  2. .AddInstances(z => z
  3. .OfConcreteType<NHFactory>()
  4. .WithName("JCDC")
  5. )
  6. .CacheBy(InstanceScope.Singleton);
  7.  
  8. using System.Reflection;
  9. using JCDCHelper.Logging.Interfaces;
  10. using JCDCHelper.NhAccess.Interfaces;
  11. using JCDCHelper.NhAccess.BusinessObjects;
  12. using JCDCHelper.Persistence.BusinessObjects;
  13. using JCDCHelper.Persistence.Interfaces;
  14. using POCAdmin3G.DAL.Interfaces;
  15. using POCAdmin3G.Jcdc.EO;
  16. using POCAdmin3G.Jcdc.Map;
  17. using StructureMap;
  18. using StructureMap.Attributes;
  19.  
  20. namespace _Test_DAL
  21. {
  22. public class _BootstrapStuctureMap
  23. {
  24. private static bool _hasStarted;
  25.  
  26. /// <summary>
  27. /// Bootstraps the structure map.
  28. /// Set up IOC for all parts of application
  29. /// Set up NHFactory for each DB with scope of one per application.
  30. /// Set up NHSession for Tran and NoTran. Give it a scope of HttpRequest or Thread
  31. /// </summary>
  32. /// <Author>fink.pete</Author>
  33. /// <CreateDate>8/31/2010</CreateDate>
  34. public void BootstrapStructureMap()
  35. {
  36. _hasStarted = true;
  37.  
  38. ObjectFactory.Initialize(x =>
  39. {
  40. x.PullConfigurationFromAppConfig = false;
  41. x.Scan(y =>
  42. {
  43. y.Assembly(Assembly.GetAssembly(typeof(IPOCContrCtrlDAL))); // TestDisplay DAL
  44. y.Assembly(Assembly.GetAssembly(typeof(IWebAccess))); // JCDCHelper Persistance
  45. y.Assembly(Assembly.GetAssembly(typeof(INHSession))); // JCDCHelper NhAccess
  46. y.Assembly(Assembly.GetAssembly(typeof(INetLog))); // JCDCHelper Logging
  47.  
  48. y.WithDefaultConventions();
  49. }
  50. );
  51.  
  52. // needed for new one WebAccess per application
  53. x.BuildInstancesOf<IWebAccess>()
  54. .TheDefaultIsConcreteType<WinFormAccess>()
  55. .CacheBy(InstanceScope.Hybrid);
  56.  
  57. // needed for new one Factory for JCDC per application
  58. x.BuildInstancesOf<INHFactory>()
  59. .AddInstances(z => z
  60. .OfConcreteType<NHFactory>()
  61. .WithName("JCDC")
  62. )
  63. .CacheBy(InstanceScope.Singleton);
  64.  
  65. // needed for NHSession for JCDC HasTran per HttpRequest
  66. x.ForRequestedType<INHSession>()
  67. .AddInstances(z => z
  68. .OfConcreteType<NHSession>()
  69. .WithName("JCDC_HasTrans")
  70. .SetProperty(y => y.DBNameAndHasTran = "JCDC_HasTrans")
  71. )
  72. .AddInstances(z => z
  73. .OfConcreteType<NHSession>()
  74. .WithName("JCDC_HasNoTrans")
  75. .SetProperty(y => y.DBNameAndHasTran = "JCDC_HasNoTrans")
  76. )
  77. .CacheBy(InstanceScope.Hybrid);
  78. });
  79.  
  80. //Debug.WriteLine(ObjectFactory.WhatDoIHave());
  81. //ObjectFactory.AssertConfigurationIsValid();
  82.  
  83. // Set up the NhibernateFactories
  84. INHFactory jcdcFactory = ObjectFactory.GetNamedInstance<INHFactory>("JCDC");
  85. jcdcFactory.BuildFactoryByConfigFile<AcademicEO, AcademicEOMap>("~/JcdcDb.config");
  86. }
  87.  
  88. /// <summary>
  89. /// Restarts StructureMap. Reset to original defaults.
  90. /// </summary>
  91. /// <Author>fink.pete</Author>
  92. /// <CreateDate>8/31/2010</CreateDate>
  93. public static void Restart()
  94. {
  95.  
  96. if (_hasStarted)
  97. {
  98. ObjectFactory.ResetDefaults();
  99. }
  100. else
  101. {
  102. Bootstrap();
  103. _hasStarted = true;
  104. }
  105. }
  106.  
  107. public static void Bootstrap()
  108. {
  109. new _BootstrapStuctureMap().BootstrapStructureMap();
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement