/// <summary>
        ///     initialise spring
        /// </summary>
        /// <returns>the application context</returns>
        public static IApplicationContext InitialiseSpring()
        {
            try
            {
                if (_context != null)
                {
                    return(_context);
                }

                List <string> assemblies             = GetAssembliesToUse();
                CodeConfigApplicationContext context = new CodeConfigApplicationContext();
                context.ScanWithAssemblyFilter(a =>
                {
                    if (assemblies.Contains(a.GetName().Name))
                    {
                        Logger.Debug($"Assembly scan added =>{a.GetName().Name}");
                        return(true);
                    }

                    Logger.Debug($"Assembly scan ignored =>{a.GetName().Name}");
                    return(false);
                });
                context.Refresh();
                _context = context;
                return(context);
            }
            catch (Exception ex)
            {
                Logger.Error($"Failed To intialise spring \n {ex}");
                throw;
            }
        }
Example #2
0
        private static IApplicationContext CreateContainerUsingCodeConfig()
        {
            CodeConfigApplicationContext ctx = new CodeConfigApplicationContext();

            ctx.ScanAllAssemblies();
            ctx.Refresh();
            return(ctx);
        }
Example #3
0
        static void Main(string[] args)
        {
            var ctx = new CodeConfigApplicationContext();

            ctx.ScanAllAssemblies();
            ctx.Refresh();
            ServiceLocator.SetLocatorProvider(() => new SpringServiceLocatorAdapter(ctx));

            var actionTest = ServiceLocator.Current.GetInstance <IActionTest>();

            //var actionTest = ctx.GetObject<IActionTest>("ccc");
            actionTest.DoSomething();

            Console.ReadKey();
        }
Example #4
0
        public XmlApplicationContext CreateBuilder(IServiceCollection services)
        {
            var rootApplicationContext = new CodeConfigApplicationContext(caseSensitive: true);

            ServiceProviderAdapter.RegisterBridges(rootApplicationContext, this.config, services);

            var applicationContext = new XmlApplicationContext(new XmlApplicationContextArgs()
            {
                CaseSensitive          = true,
                Name                   = "root",
                ConfigurationLocations = this.config.ConfigLocations.AsEnumerable(),
                ParentContext          = rootApplicationContext
            });

            ServiceProviderAdapter.Adapt(services, applicationContext, this.config);

            return(applicationContext);
        }
Example #5
0
 public void _SetUp()
 {
     _scanner = new AssemblyObjectDefinitionScanner();
     _context = new CodeConfigApplicationContext();
 }