private IContainer ConfigureIOC(IServiceCollection services)
        {
            var container = new global::StructureMap.Container();

            container.Configure(config =>
            {
                config.Scan(_ =>
                {
                    _.AssemblyContainingType(typeof(Startup));
                    _.WithDefaultConventions();
                    _.SingleImplementationsOfInterface();
                });


                config.For <IConfiguration>().Use(Configuration);

                //config.Scan(scanner =>
                //{
                //});

                config.For <ISender>().Use <Sender>();

                config.AddRegistry <NServiceBusClientUnitOfWorkRegistry>();
                config.AddRegistry <UnitOfWorkRegistry>();

                config
                .For <DbTransaction>()
                .Use(c => GetSqlSessionFromContext(c).Transaction);
            });

            return(container);
        }
 private static global::StructureMap.Container GetStructuremapContainer()
 {
     var registry = new DefaultStructureMapRegistry();
     var container = new global::StructureMap.Container(registry);
     container.AssertConfigurationIsValid();
     return container;
 }
        /// <summary>
        /// Creates the container adapter.
        /// </summary>
        /// <returns></returns>
        protected override ContainerAdapter CreateAdapter()
        {
            IContainer container = new Container();

            container.Configure(x => x.For<HttpContextBase>().Use(() => new HttpContextWrapper(HttpContext.Current)));

            return new StructureMapAdapter(container);
        }
        /// <summary>
        /// Creates the container adapter.
        /// </summary>
        /// <returns></returns>
        protected override ContainerAdapter CreateAdapter()
        {
            IContainer container = new Container();

            container.Configure(x => x.For <HttpContextBase>().Use(() => new HttpContextWrapper(HttpContext.Current)));

            return(new StructureMapAdapter(container));
        }
Beispiel #5
0
        private static void Main(string[] args)
        {
            DoStuff();
            Console.WriteLine();

            DoAnotherStuff();
            Console.WriteLine();

            DoMoreStuff();
            Console.WriteLine();

            DoBetterStuff();
            Console.WriteLine();

            InterceptedViaInjection();
            Console.WriteLine();

            #region Autofac adapter demo

            // autofac container
            var afContainerBuilder = new ContainerBuilder();

            afContainerBuilder
            .RegisterType <InterceptorForContainer>()
            .As <ITypedInterceptor>();

            var afContainer = afContainerBuilder.Build();

            // cop adapter
            var afCopAdapter = new CodeCop.Setup.Autofac.AutofacContainerAdapter(afContainer);

            #endregion

            #region Castle.Windsor adapter demo

            var cwContainer = new WindsorContainer();

            cwContainer.Register(
                Component
                .For <ITypedInterceptor>()
                .ImplementedBy <InterceptorForContainer>()
                );

            var cwCopAdapter = new CodeCop.Setup.Castle.Windsor.CastleWindsorContainerAdapter(cwContainer);

            #endregion

            #region Ninject adapter demo

            var nContainer = new StandardKernel();

            nContainer
            .Bind <ITypedInterceptor>()
            .To <InterceptorForContainer>();

            var nCopAdapter = new CodeCop.Setup.Ninject.NinjectContainerAdapter(nContainer);

            #endregion

            #region StructureMap adapter demo

            var smContainer = new global::StructureMap.Container();

            smContainer
            .Configure(c =>
            {
                c.For <ITypedInterceptor>()
                .Use <InterceptorForContainer>();
            });

            var smCopAdapter = new CodeCop.Setup.StructureMap.StructureMapContainerAdapter(smContainer);

            #endregion

            #region Unity adapter demo

            var uContainer = new Microsoft.Practices.Unity.UnityContainer();

            uContainer.RegisterType <ITypedInterceptor, InterceptorForContainer>();

            var uCopAdapter = new CodeCop.Setup.Unity.UnityContainerAdapter(uContainer);

            #endregion

            Setup
            .Build(afCopAdapter)     // pass the adapter
            .InterceptMethodIn <Program>(nameof(DoStuff), Intercept.Before,
                                         ctx =>
            {
                Console.WriteLine("InterceptOn.Before > DoStuff !");
                return(null);
            })
            .InterceptMethodIn <Program>(nameof(DoAnotherStuff), new MyInterceptor())
            .UseInterceptor(new ProgramTypedInterceptor())
            .Create()
            .Activate();

            DoStuff();
            Console.WriteLine();

            DoAnotherStuff();
            Console.WriteLine();

            DoMoreStuff();
            Console.WriteLine();

            DoBetterStuff();
            Console.WriteLine();

            InterceptedViaInjection();
            Console.WriteLine();
        }
Beispiel #6
0
        private static void Main(string[] args)
        {

            DoStuff();
            Console.WriteLine();

            DoAnotherStuff();
            Console.WriteLine();

            DoMoreStuff();
            Console.WriteLine();

            DoBetterStuff();
            Console.WriteLine();

            InterceptedViaInjection();
            Console.WriteLine();

            #region Autofac adapter demo
            
            // autofac container
            var afContainerBuilder = new ContainerBuilder();

            afContainerBuilder
                .RegisterType<InterceptorForContainer>()
                .As<ITypedInterceptor>();

            var afContainer = afContainerBuilder.Build();

            // cop adapter
            var afCopAdapter = new CodeCop.Setup.Autofac.AutofacContainerAdapter(afContainer);

            #endregion

            #region Castle.Windsor adapter demo

            var cwContainer = new WindsorContainer();

            cwContainer.Register(
                Component
                    .For<ITypedInterceptor>()
                    .ImplementedBy<InterceptorForContainer>()
                );

            var cwCopAdapter = new CodeCop.Setup.Castle.Windsor.CastleWindsorContainerAdapter(cwContainer);

            #endregion

            #region Ninject adapter demo

            var nContainer = new StandardKernel();

            nContainer
                .Bind<ITypedInterceptor>()
                .To<InterceptorForContainer>();

            var nCopAdapter = new CodeCop.Setup.Ninject.NinjectContainerAdapter(nContainer);

            #endregion

            #region StructureMap adapter demo

            var smContainer = new global::StructureMap.Container();

            smContainer
                .Configure(c =>
                {
                    c.For<ITypedInterceptor>()
                     .Use<InterceptorForContainer>();
                });

            var smCopAdapter = new CodeCop.Setup.StructureMap.StructureMapContainerAdapter(smContainer);

            #endregion

            #region Unity adapter demo

            var uContainer = new Microsoft.Practices.Unity.UnityContainer();

            uContainer.RegisterType<ITypedInterceptor, InterceptorForContainer>();

            var uCopAdapter = new CodeCop.Setup.Unity.UnityContainerAdapter(uContainer);

            #endregion

            Setup
                .Build(afCopAdapter) // pass the adapter
                .InterceptMethodIn<Program>(nameof(DoStuff), Intercept.Before,
                    ctx =>
                    {
                        Console.WriteLine("InterceptOn.Before > DoStuff !");
                        return null;
                    })
                .InterceptMethodIn<Program>(nameof(DoAnotherStuff), new MyInterceptor())
                .UseInterceptor(new ProgramTypedInterceptor())
                .Create()
                .Activate();

            DoStuff();
            Console.WriteLine();

            DoAnotherStuff();
            Console.WriteLine();

            DoMoreStuff();
            Console.WriteLine();

            DoBetterStuff();
            Console.WriteLine();

            InterceptedViaInjection();
            Console.WriteLine();

        }