예제 #1
0
파일: Program.cs 프로젝트: zedr0n/hycon-es
        private void Initialise()
        {
            var root = new CompositionRoot();

            root.ComposeApplication(_container);
            _container.Collection.Register <IHyconListener>(
                typeof(CreateBlockListener),
                typeof(PutBlockListener),
                typeof(ListBlockListener));
            _container.Verify();
        }
예제 #2
0
        static void Main(string[] args)
        {
            IServiceCollection serviceCollection = new ServiceCollection();

            CompositionRoot.ComposeApplication(serviceCollection);

            IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            CustomerRegistrationService service = serviceProvider.GetService <CustomerRegistrationService>();

            service.Register(new CustomerDTO());

            Console.ReadLine();
        }
예제 #3
0
        /// <summary>
        /// Wires the root queries and mutations for multiple domains defined by their respective config types
        /// </summary>
        /// <param name="services"><see cref="IServiceCollection"/></param>
        /// <param name="container"><see cref="SimpleInjector"/> container</param>
        /// <param name="configs">Config types containing the domain registration, root queries and mutations</param>
        /// <param name="logger">Logger instance ( for XUnit )</param>
        /// <param name="useRemoteStore">Use remote store</param>
        private static void UseGraphQl(this IServiceCollection services, Container container, IEnumerable <Type> configs, ILogger logger = null, bool useRemoteStore = false)
        {
            container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
            var root = new CompositionRoot();

            root.ComposeApplication(container);
            container.Register(() => services, Lifestyle.Singleton);
            container.Register <ISchemaProvider, SchemaProvider>(Lifestyle.Singleton);
            container.Register <IDiagnosticObserver, DiagnosticObserver>(Lifestyle.Singleton);
            if (useRemoteStore)
            {
                root.RegisterRemoteStore(container, false);
            }

            if (logger != null)
            {
                container.Options.AllowOverridingRegistrations = true;
                container.Register(typeof(ILogger), () => logger, Lifestyle.Singleton);
                container.Options.AllowOverridingRegistrations = false;
            }
            else
            {
                var config = Logging.NLog.Configure();
                Logging.NLog.Enable(config);
            }

            foreach (var t in configs)
            {
                var regMethod = t.GetMethods(BindingFlags.Static | BindingFlags.Public)
                                .SingleOrDefault(x => x.GetCustomAttribute <RegistrationAttribute>() != null);

                regMethod?.Invoke(null, new object[] { container });
            }

            // container.Verify();
            root.Verify(container);

            services.AddSingleton(typeof(Container), t => container);
        }