コード例 #1
0
ファイル: DepsCatalog.cs プロジェクト: 2garryn/wpay
 private string PrepareCategory(IServiceDefinition def, Type implType) =>
 $"[{def.GetType().Name}({def.Label()}): {implType.Name}]";
コード例 #2
0
        public void Configure(IServiceDefinition service, AttributeSet attributes)
        {
            if (ReferenceEquals(service, null))
            {
                return;
            }

            var validationErrros = _attributeMatrix.Validate <IServiceDefinition>(attributes);

            if (validationErrros != null)
            {
                var message = "There are invalid attributes on service of type " + service.GetType().DisplayName();

                if (attributes.IsService != null && string.IsNullOrEmpty(attributes.IsService.Name))
                {
                    message += " called '" + attributes.IsService.Name + "'.";
                }

                foreach (var error in validationErrros)
                {
                    message += Environment.NewLine + error;
                }

                throw new ServiceBuilderException(message);
            }

            if (!ReferenceEquals(attributes.IsService, null))
            {
                service.Name(attributes.IsService.Name);
            }

            if (!ReferenceEquals(attributes.NeedsDatas, null))
            {
                foreach (var dataNeed in attributes.NeedsDatas)
                {
                    if (!string.IsNullOrEmpty(dataNeed.DataProviderName))
                    {
                        service.DataProvider(dataNeed.DataProviderName);
                    }
                    if (dataNeed.DataType != null)
                    {
                        service.BindTo(dataNeed.DataType, dataNeed.Scope);
                    }
                }
            }

            if (!ReferenceEquals(attributes.PartOf, null))
            {
                service.PartOf(attributes.PartOf.PackageName);
            }

            if (!ReferenceEquals(attributes.DeployedAs, null))
            {
                service
                .DeployIn(attributes.DeployedAs.ModuleName)
                .AssetDeployment(attributes.DeployedAs.Deployment);
            }

            if (!ReferenceEquals(attributes.Routes, null))
            {
                foreach (var route in attributes.Routes)
                {
                    service.Route(route.Path, route.Priority, route.Methods);
                }
            }

            if (!ReferenceEquals(attributes.DataScopes, null))
            {
                foreach (var dataScope in attributes.DataScopes)
                {
                    service.DataScope(dataScope.DataType, dataScope.Scope);
                }
            }
        }