///<summary>
        ///Initializes the provider.
        ///</summary>
        ///
        ///<param name="config">A collection of the name/value pairs representing the provider-specific
        /// attributes specified in the configuration for this provider.
        /// The <c>providerId</c> attribute may be used to override the name being used for looking up an object definition.
        /// </param>
        ///<param name="name">The friendly name of the provider.</param>
        ///<exception cref="T:System.ArgumentNullException">The <paramref name="name"/> or <paramref name="config"/> is null.</exception>
        ///<exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
        ///<exception cref="T:System.ArgumentException">The <paramref name="name"/> has a length of zero or providerId attribute is not set.</exception>
        public override void Initialize(string name, NameValueCollection config)
        {
            lock (this)
            {
                if (config == null)
                {
                    throw new ArgumentNullException("config");
                }

                string providerId = config["providerId"];
                if (String.IsNullOrEmpty(providerId))
                {
                    providerId = name;
                }
                config.Remove("providerId");

                this.wrappedProvider = (RoleProvider)WebApplicationContext.GetRootContext().GetObject(providerId);
                this.wrappedProvider.Initialize(name, config);
            }
        }
Example #2
0
        /// <summary>
        /// Creates the configured BetterCMS root dependencies container.
        /// </summary>
        /// <returns>The container builder.</returns>
        public static ContainerBuilder InitializeContainer(ContainerBuilder builder = null)
        {
            if (builder == null)
            {
                builder = new ContainerBuilder();
            }

            if (isStarted)
            {
                return(builder);
            }

            builder = WebApplicationContext.InitializeContainer(builder, Config);
            builder.RegisterType <DefaultTextEncryptor>().As <ITextEncryptor>().SingleInstance();

            builder.RegisterType <CmsModulesRegistration>()
            .As <IModulesRegistration>()
            .As <IWebModulesRegistration>()
            .As <ICmsModulesRegistration>()
            .SingleInstance();

            builder.RegisterInstance(Config)
            .As <ICmsConfiguration>()
            .As <IWebConfiguration>()
            .As <IConfiguration>()
            .SingleInstance();

            builder.RegisterType <DefaultCmsHost>()
            .As <IWebApplicationHost>()
            .As <ICmsHost>()
            .SingleInstance();

            RegisterCacheService(builder);
            RegisterStorageService(builder);

            isStarted = true;

            return(builder);
        }
Example #3
0
        public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            //get spring context
            WebApplicationContext ctx = ContextRegistry.GetContext() as WebApplicationContext;
            string controller         = controllerName + "Controller";

            //查找是否配置该Controller
            if (ctx.ContainsObject(controller))
            {
                object controllerf = ctx.GetObject(controller);
                return((IController)controllerf);
            }
            else
            {
                if (defalutf == null)
                {
                    defalutf = new DefaultControllerFactory();
                }

                return(defalutf.CreateController(requestContext, controllerName));
            }
        }
Example #4
0
        public void RunTestWithDI()
        {
//            LogManager.Adapter = new Common.Logging.Simple.TraceLoggerFactoryAdapter();

            DataView dv = CreateDataSource();

            using (TestWebContext wctx = new TestWebContext("/testpath", "testpage.aspx"))
            {
                IApplicationContext ctx = new WebApplicationContext();

                int runs = 1000;

                StopWatch watch = new StopWatch();
                using (watch.Start("Duration: {0}"))
                {
                    for (int i = 0; i < runs; i++)
                    {
                        DataGrid grid = new DataGrid();
                        Spring.Web.Support.WebDependencyInjectionUtils.InjectDependenciesRecursive(ctx, grid);
                        grid.DataSource = dv;
                        grid.DataBind();
                    }
                }

                using (watch.Start("Duration: {0}"))
                {
                    for (int i = 0; i < runs; i++)
                    {
                        DataGrid grid = new DataGrid();
                        grid.DataSource = dv;
                        grid.DataBind();
                        Spring.Web.Support.WebDependencyInjectionUtils.InjectDependenciesRecursive(ctx, grid);
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Method to run logic before application start (as PreApplicationStartMethod). Do not run this method from your code.
        /// </summary>
        public static void PreApplicationStart()
        {
            if (isStarted)
            {
                return;
            }

            ILog logger;

            try
            {
                logger = LogManager.GetCurrentClassLogger();
                logger.Info("Starting Web Application...");
            }
            catch (Exception ex)
            {
                throw new CoreException("Logging is not working. A reason may be that Common.Logging section is not configured in web.config.", ex);
            }

            try
            {
                logger.Info("Creating Web Application context dependencies container...");
                ContextScopeProvider.RegisterTypes(WebApplicationContext.InitializeContainer());
            }
            catch (Exception ex)
            {
                string message = "Failed to create Web Application context dependencies container.";
                logger.Fatal(message, ex);

                throw new CoreException(message, ex);
            }

            PreStartWebApplication();

            isStarted = true;
        }
Example #6
0
 public DepartmentService(WebApplicationContext context)
 {
     _context = context;
 }
 public EmployeeService(WebApplicationContext dbContext)
 {
     _dbContext = dbContext;
 }
 public UnitOfWork(IDatabaseFactory databaseFactory)
 {
     this.databaseFactory = databaseFactory;
     this.dbContext       = this.databaseFactory.Get();
 }
Example #9
0
 public FeedbacksController(WebApplicationContext context)
 {
     _context = context;
 }
 public SeedingService(WebApplicationContext context)
 {
     _context = context;
 }
Example #11
0
 /// <summary>
 /// Returns the unchecked, raw application context for the given virtual path.
 /// </summary>
 /// <param name="virtualPath">the virtual path to get the context for.</param>
 /// <returns>the context or null.</returns>
 /// <remarks>
 /// Subclasses may override this method to change the context source.
 /// By default, <see cref="WebApplicationContext.GetContext"/> is used for obtaining context instances.
 /// </remarks>
 protected virtual IApplicationContext GetContext(string virtualPath)
 {
     return(WebApplicationContext.GetContext(virtualPath));
 }
 public HomeController(WebApplicationContext context)
 {
     _context = context;
 }
 public UsersController(WebApplicationContext context)
 {
     _context = context;
 }
 public SellerService(WebApplicationContext context)
 {
     _context = context;
 }
Example #15
0
 public JobService(WebApplicationContext context)
 {
     _context = context;
 }
 public EmployeesController(WebApplicationContext dataContext)
 {
     _dataContext = dataContext;
 }
 public VendedorService(WebApplicationContext context)
 {
     _context = context;
 }
 public SalesRecordService(WebApplicationContext context)
 {
     _context = context;
 }
Example #19
0
 public Startup(IConfiguration configuration)
 {
     Configuration         = configuration;
     WebApplicationContext = new WebApplicationContext();
 }
 public DepartmentsController(WebApplicationContext context)
 {
     _context = context;
 }
Example #21
0
        /// <summary>
        /// Retrieves instance of the page from Spring web application context.
        /// </summary>
        /// <param name="context">current HttpContext</param>
        /// <param name="requestType">type of HTTP request (GET, POST, etc.)</param>
        /// <param name="url">requested page URL</param>
        /// <param name="path">translated server path for the page</param>
        /// <returns>instance of the configured page object</returns>
        IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string path)
        {
            new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand();

            IConfigurableApplicationContext appContext =
                WebApplicationContext.GetContext(url) as IConfigurableApplicationContext;

            if (appContext == null)
            {
                throw new InvalidOperationException(
                          "Implementations of IApplicationContext must also implement IConfigurableApplicationContext");
            }

            string appRelativeVirtualPath = WebUtils.GetAppRelativePath(url);

            AbstractHandlerFactory.NamedObjectDefinition nod =
                AbstractHandlerFactory.FindWebObjectDefinition(appRelativeVirtualPath, appContext.ObjectFactory);

            Type serviceType = null;

            if (nod != null)
            {
#if !MONO
                if (appContext.IsTypeMatch(nod.Name, typeof(WebServiceExporter)))
                {
                    WebServiceExporter wse = (WebServiceExporter)appContext.GetObject(nod.Name);
                    serviceType = wse.GetExportedType();
                }
                else
                {
                    serviceType = appContext.GetType(nod.Name);
                    // check if the type defines a Web Service
                    object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true);
                    if (wsAttribute.Length == 0)
                    {
                        serviceType = null;
                    }
                }
#else
                serviceType = appContext.GetType(nod.Name);

                // check if the type defines a Web Service
                object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true);
                if (wsAttribute.Length == 0)
                {
                    serviceType = null;
                }
#endif
            }

            if (serviceType == null)
            {
                serviceType = WebServiceParser.GetCompiledType(url, context);
            }


#if !MONO_2_0
            return((IHttpHandler)CoreGetHandler.Invoke(this, new object[] { serviceType, context, context.Request, context.Response }));
#else
            // find if the BuildManager already contains a cached value of the service type
            var buildCacheField = typeof(BuildManager).GetField("buildCache", BindingFlags.Static | BindingFlags.NonPublic);
            var buildCache      = (IDictionary)buildCacheField.GetValue(null);

            if (!buildCache.Contains(appRelativeVirtualPath))
            {
                // create new fake BuildManagerCacheItem wich represent the target type
                var buildManagerCacheItemType = Type.GetType("System.Web.Compilation.BuildManagerCacheItem, System.Web");
                var cacheItemCtor             = buildManagerCacheItemType.GetConstructor(new Type[] { typeof(Assembly), typeof(BuildProvider), typeof(CompilerResults) });
                var buildProvider             = new FakeBuildProvider(serviceType);
                var cacheItem = cacheItemCtor.Invoke(new object[] { serviceType.Assembly, buildProvider, null });

                // store it in the BuildManager
                buildCache [appRelativeVirtualPath] = cacheItem;
            }

            // now that the target type is in the cache, let the default process continue
            return(base.GetHandler(context, requestType, url, path));
#endif
        }
Example #22
0
 public WebApplicationContext Get()
 {
     return(dataContext ?? (dataContext = new WebApplicationContext()));
 }
Example #23
0
 public ClassesController(WebApplicationContext context)
 {
     _context = context;
 }
 public CommentsController(WebApplicationContext context)
 {
     _context = context;
 }
 public VotesController(WebApplicationContext context)
 {
     _context = context;
 }
Example #26
0
 public AccountController(WebApplicationContext context)
 {
     _context = context;
 }