Exemple #1
0
        /// <summary>
        /// Creates a new child kernel with all the bindings
        /// </summary>
        /// <returns>A kernel wrapper that wraps the actual kernel.</returns>
        private IKernelWrapper CreateNewChildKernel()
        {
            INinjectModule dataGridBindings = null;

            try
            {
                dataGridBindings = new DataGridBindings();
            }
            catch
            {
                // Swallow exception and use alternate bindings
                dataGridBindings = new NoDataGridBindings();
            }

            var kernelFactory = new KernelFactory(new ServiceBindings(), dataGridBindings);
            var eventKernel   = kernelFactory.GetChildKernel(this.parentKernel, AgentConfiguration.DefaultBindingsExclusionList);

            eventKernel.Bind <IEventRunner>().To <EventRunner>().InTransientScope();
            eventKernel.Bind <ILogger>().ToMethod(LoggerFactory.GetLogger).InTransientScope();
            eventKernel.Bind <DatabaseLogger>()
            .ToConstructor(x => new DatabaseLogger(
                               x.Inject <ILogRepository>(),
                               x.Inject <ILogService>(),
                               x.Inject <ILogContext>(),
                               x.Inject <IEventRepository>(),
                               x.Inject <IAgentService>()))
            .InTransientScope();
            var childKernelWrapper = new ChildKernelWrapper(eventKernel, this.AddFreeChildKernels);

            this.childKernels.Add(childKernelWrapper);
            return(childKernelWrapper);
        }
Exemple #2
0
        public static IKernel GetKernel(IList <INinjectModule> baseBindings, IList <Type> excludedTypes = null)
        {
            INinjectModule dataGridBindings = null;

            try
            {
                dataGridBindings = new DataGridBindings();
            }
            catch
            {
                // Swallow exception and use alternate bindings
                dataGridBindings = new NoDataGridBindings();
            }

            var bindings = new List <INinjectModule> {
                new ServiceBindings(), dataGridBindings
            };

            bindings.AddRange(baseBindings);

            var allBindings = bindings.Where(e => e != null).ToArray();

            return(new KernelFactory(allBindings).GetKernel(excludedTypes));
        }