Ejemplo n.º 1
0
        //Register Container for classes that use dependecy Injection
        private Container ConfigureSimpleInjector(IAppBuilder app)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();

            container.Register<IUserStore<User, int>, UserStore>(Lifestyle.Scoped);

            container.Register<IDatabaseFactory, DatabaseFactory>(Lifestyle.Scoped);

            container.Register<IUnitOfWork, UnitOfWork>();

            container.Register<IAuthRepository, AuthRepository>();
            container.Register<ICommentRepository, CommentRepository>();
            container.Register<IUserRepository, UserRepository>();
            container.Register<ICompanyProfileRepository, CompanyProfileRepository>();
            container.Register<IInsuranceAgentProfileRepository, InsuranceAgentProfileRepository>();
            container.Register<ILeadProductRepository, LeadProductRepository>();
            container.Register<ILeadTransactionRepository, LeadTransactionRepository>();
            container.Register<IReviewPostRepository, ReviewPostRepository>();

            app.Use(async (context, next) => {
                    using (container.BeginExecutionContextScope())
                    {
                        await next();
                    }
                });

            container.Verify();

            return container;
        }
Ejemplo n.º 2
0
        public void Configuration(IAppBuilder app)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
            InitializeContainer(container);
            container.Verify();

            app.Use(async(context, next) =>
            {
                using (container.BeginExecutionContextScope())
                {
                    await next();
                }
            });

            var config = new HttpConfiguration();

            ConfigureOAuth(app);

            //config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(this.Container);

            WebApiConfig.Register(config);
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            //app.UseWebApi(config);
        }
 public static void UseOwinContextInjector(this IAppBuilder app, Container container)
 {
     // Create an OWIN middleware to create an execution context scope
     app.Use(async (context, next) =>
     {
         using (var scope = container.BeginExecutionContextScope())
         {
             await next.Invoke();
         }
     });
 }
        /// <summary>Wraps an ASP.NET request in a execution context scope.</summary>
        /// <param name="applicationBuilder">The ASP.NET application builder instance that references all
        /// framework components.</param>
        /// <param name="container"></param>
        public static void UseSimpleInjectorAspNetRequestScoping(this IApplicationBuilder applicationBuilder,
                                                                 Container container)
        {
            Requires.IsNotNull(applicationBuilder, nameof(applicationBuilder));
            Requires.IsNotNull(container, nameof(container));

            applicationBuilder.Use(async(context, next) =>
            {
                using (container.BeginExecutionContextScope())
                {
                    await next();
                }
            });
        }
        /// <summary>Wraps an ASP.NET request in a execution context scope.</summary>
        /// <param name="applicationBuilder">The ASP.NET application builder instance that references all
        /// framework components.</param>
        /// <param name="container"></param>
        public static void UseSimpleInjectorAspNetRequestScoping(this IApplicationBuilder applicationBuilder,
            Container container)
        {
            Requires.IsNotNull(applicationBuilder, nameof(applicationBuilder));
            Requires.IsNotNull(container, nameof(container));

            applicationBuilder.Use(async (context, next) =>
            {
                using (container.BeginExecutionContextScope())
                {
                    await next();
                }
            });
        }
Ejemplo n.º 6
0
        public static void ConfigureDependencies(HttpConfiguration config, IAppBuilder app)
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
            container.RegisterWebApiControllers(GlobalConfiguration.Configuration);

            ConfigContainer(container);
            container.Verify();

            app.Use(async (context, next) =>
            {
                using (container.BeginExecutionContextScope())
                {
                    await next();
                }
            });

            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
        }
        public void Configuration(IAppBuilder app)
        {
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888

            //See here:
            //https://chanmingman.wordpress.com/2015/01/01/implement-ssl-in-self-hosted-web-api/
            //https://pfelix.wordpress.com/2012/02/26/enabling-https-with-self-hosted-asp-net-web-api/
            //https://katanaproject.codeplex.com/discussions/545123
            var config = new HttpConfiguration();
            config.Routes.MapHttpRoute("DefaultApi", "1.0/{controller}/{id}", new { id = RouteParameter.Optional });
            app.UseWebApi(config);


            var container = new Container();
            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();

            container.RegisterSingleton(Mapper.Engine);

            container.Register<IAnime, Anime>();
            container.Register<IAnimeOriginalJson, AnimeOriginalJson>();
            container.Register<IAnimeFactory, AnimeFactory>(Lifestyle.Singleton);
            container.Register<IAnimeRetriever, AnimeRetriever>(Lifestyle.Singleton);
            container.Register<IMappingToJson, MappingToJson>(Lifestyle.Singleton);
            container.Register<IAnimeHandler, AnimeHandler>(Lifestyle.Singleton);
            container.Register<ICacheHandler, CacheHandler>(Lifestyle.Singleton);

            container.RegisterWebApiControllers(config);

            container.Verify();

            config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);

            app.Use(async (context, next) =>
            {
                using (container.BeginExecutionContextScope())
                {
                    await next();
                }
            });



        }
 public SimpleInjectorScope(Container container)
 {
     _container = container;
     _container.BeginExecutionContextScope();
 }
Ejemplo n.º 9
0
        // Register containers for classes that use dependency injection
        private Container ConfigureSimpleInjector(IAppBuilder app)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();

            container.Register<IUserStore<User, int>, UserStore>(Lifestyle.Scoped);
            container.Register<IAuthRepository, AuthRepository>(Lifestyle.Scoped);

            container.Register<IDatabaseFactory, DatabaseFactory>(Lifestyle.Scoped);

            container.Register<IUnitOfWork, UnitOfWork>();

            container.Register<IBlogRepository, BlogRepository>();
            container.Register<IPostRepository, PostRepository>();
            container.Register<IUserRepository, UserRepository>();
            container.Register<IExternalLoginRepository, ExternalLoginRepository>();

            container.Register<IBlogService, BlogService>();
            container.Register<IWordPressBlogReader, WordPressBlogReader>();

            //container.RegisterConditional(
            //    typeof(ILogger),
            //    c => typeof(Logger).MakeGenericType(c.Consumer.ImplementationType),
            //                  Lifestyle.Transient,
            //                    c => true);

            app.Use(async (context, next) =>
            {
                using (container.BeginExecutionContextScope())
                {
                    await next();
                }
            });

            container.Verify();

            return container;
        }
        // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
        public void ConfigureAuth(IAppBuilder app)
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new ExecutionContextScopeLifestyle();
            container.Register<IUserIdentityApplicationService, UserIdentityApplicationService>(Lifestyle.Scoped);
            container.Verify();

            app.Use(
                async (context, next) =>
                {
                    using (container.BeginExecutionContextScope())
                    {
                        await next();
                    }
                });

            // Configure the db context, user manager and signin manager to use a single instance per request
            AppBuilderExtensions.CreatePerOwinContext(app, () => new ApplicationDbContext());
            //app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
            //app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

            AppBuilderExtensions.CreatePerOwinContext<ApplicationUserManager>(app, ApplicationUserManager.Create);
            AppBuilderExtensions.CreatePerOwinContext<ApplicationSignInManager>(app, ApplicationSignInManager.Create);

            var securityStampValidator = new SecurityStampValidator(null, null);
            // Enable the application to use a cookie to store information for the signed in user
            // and to use a cookie to temporarily store information about a user logging in with a third party login provider
            // Configure the sign in cookie
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = AuthenticationType.ApplicationCookie,
                LoginPath = new PathString("/Account/Login"),
                Provider = new CookieAuthenticationProvider
                {
                    // Enables the application to validate the security stamp when the user logs in.
                    // This is a security feature which is used when you change a password or add an external login to your account.  
                    OnValidateIdentity = securityStampValidator.OnValidateIdentity
                }
            });
            app.UseExternalSignInCookie(AuthenticationType.ExternalCookie);

            // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
            app.UseTwoFactorSignInCookie(AuthenticationType.TwoFactorCookie, TimeSpan.FromMinutes(5));

            // Enables the application to remember the second login verification factor such as phone or email.
            // Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
            // This is similar to the RememberMe option when you log in.
            app.UseTwoFactorRememberBrowserCookie(AuthenticationType.TwoFactorRememberBrowserCookie);

            // Uncomment the following lines to enable logging in with third party login providers
            //app.UseMicrosoftAccountAuthentication(
            //    clientId: "",
            //    clientSecret: "");

            //app.UseTwitterAuthentication(
            //   consumerKey: "",
            //   consumerSecret: "");

            //app.UseFacebookAuthentication(
            //   appId: "",
            //   appSecret: "");

            //app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
            //{
            //    ClientId = "",
            //    ClientSecret = ""
            //});
        }