Пример #1
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary>
        ///  Loads an extension.
        /// </summary>
        /// <exception cref="Exception">
        ///  Thrown when an exception error condition occurs.
        /// </exception>
        /// <param name="extensionName">
        ///  The name of the extension.
        /// </param>
        /// <param name="configuration">
        ///  (Optional) the configuration.
        /// </param>
        /// <returns>
        ///  The extension.
        /// </returns>
        ///-------------------------------------------------------------------------------------------------
        public virtual async Task <IDomainScope> CreateScopeAsync(string extensionName, IDomainConfiguration configuration = null)
        {
            Contract.RequiresNotEmpty(extensionName, "extensionName");
            CheckInitialized();

            if (this is ISchema)
            {
                throw new HyperstoreException("Can not create a scope for a schema. Uses LoadSchemaExtension for a schema");
            }

            Conventions.CheckValidDomainName(extensionName);
            if ((Store.Options & StoreOptions.EnableScopings) != StoreOptions.EnableScopings)
            {
                throw new HyperstoreException("Scoping are not enabled. Use EnableScoping when instancing the store.");
            }

            var services = Services.NewScope();

            // Removed graphadapter from services
            services.Register <IGraphAdapter>(null);

            var domain = await((IDomainManager)Store).CreateDomainModelAsync(extensionName, configuration, services,
                                                                             (r, name) => new Scopes.DomainScope(r, ((IDomainModel)this).Name, extensionName, this)
                                                                             );

            return((IDomainScope)domain);
        }