Ejemplo n.º 1
0
        public void Setup()
        {
            var winsorContainer = new WindsorContainer();

            AspectsConfigurator
            .UseContainer(new WindsorAspectsContainer(winsorContainer))
            .Initialize();

            winsorContainer.Register(
                Component
                .For <IServiceForBenchmark>()
                .ImplementedBy <ServiceForBenchmark>());

            _windsorService = winsorContainer.Resolve <IServiceForBenchmark>();

            _reflectedMethodService = new ServiceForBenchmark();
            _reflectedMethod        = typeof(IServiceForBenchmark).GetMethod(nameof(IServiceForBenchmark.Identity));

            var weaver = AspectWeaverFactory.Create();

            _weavedService = (IServiceForBenchmark)weaver.Weave(
                new ServiceForBenchmark(), typeof(IServiceForBenchmark), typeof(ServiceForBenchmark));

            _proxiedService = (IServiceForBenchmark)BypassProxy <IServiceForBenchmark> .Create(
                new ServiceForBenchmark());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Выполняет привязку аспектов к сервисам.
        /// Важно: вызов данного метода должен распологаться после регистрации
        /// всех зависимостей.
        /// </summary>
        /// <param name="serviceCollection">Коллекция сервисов.</param>
        /// <returns>Коллекция сервисов.</returns>
        public static IServiceCollection UseAspectsWeaving(
            this IServiceCollection serviceCollection)
        {
            AspectsConfigurator
            .UseContainer(new MicrosoftAspectContainer(serviceCollection))
            .Initialize();

            return(serviceCollection);
        }
Ejemplo n.º 3
0
        private static Container CreateContainer()
        {
            var container = new Container();

            AspectsConfigurator
            .UseContainer(new SimpleInjectorAspectContainer(container))
            .Initialize();

            container.Register <ICustomerService, CustomerService>();

            return(container);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Выполняет привязку аспектов к сервисам.
        /// Важно: вызов данного метода должен распологаться после регистрации
        /// всех зависимостей.
        /// </summary>
        /// <param name="serviceCollection">Коллекция сервисов.</param>
        /// <param name="configuration">Конфигурация.</param>
        /// <returns>Коллекция сервисов.</returns>
        public static IServiceCollection UseAspectsWeaving(
            this IServiceCollection serviceCollection, Action <AspectsConfiguration> configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            AspectsConfigurator
            .UseContainer(new MicrosoftAspectContainer(serviceCollection))
            .Initialize(configuration);

            return(serviceCollection);
        }
Ejemplo n.º 5
0
        private static WindsorContainer CreateContainer()
        {
            var container = new WindsorContainer();

            AspectsConfigurator
            .UseContainer(new WindsorAspectsContainer(container))
            .Initialize();

            container.Register(
                Component.For <IWebPageService>()
                .ImplementedBy <WebPageService>());

            return(container);
        }
Ejemplo n.º 6
0
        private static Container CreateContainer()
        {
            var container = new Container();

            AspectsConfigurator
            .UseContainer(new SimpleInjectorAspectContainer(container))
            .Initialize(cfg =>
            {
                cfg.UseClassAspectSelection();
            });

            container.Register <IDataService, DataService>();

            return(container);
        }
Ejemplo n.º 7
0
        private void InitializeSimpleInjector(IEnumerable <DependencyPair> dependency)
        {
            AspectsConfigurator
            .UseContainer(new SimpleInjectorAspectContainer(_simpleInjectorContainer))
            .Initialize(s =>
            {
                if (_configurator != null)
                {
                    _configurator(s);
                }
            });

            _simpleInjectorContainer.Register <TService, TImplementation>();

            foreach (var pair in dependency)
            {
                _simpleInjectorContainer.Register(pair.ServiceType, pair.ImplementationType);
            }
        }
Ejemplo n.º 8
0
        private void InitializeWindsor(IEnumerable <DependencyPair> dependency)
        {
            AspectsConfigurator
            .UseContainer(new WindsorAspectsContainer(_windsorContainer))
            .Initialize(s =>
            {
                if (_configurator != null)
                {
                    _configurator(s);
                }
            });

            _windsorContainer.Register(
                Component
                .For <TService>()
                .ImplementedBy <TImplementation>());

            foreach (var pair in dependency)
            {
                _windsorContainer.Register(Component.For(pair.ServiceType).ImplementedBy(pair.ImplementationType));
            }
        }