Example #1
0
        public StoreApplication(
            IComponentContext context,
            IStoreService storeService,
            IStoreRepository storeRepository,
            IApplicationRepository applicationRepository,
            IApplicationStoreService applicationStoreService,
            IApplicationStoreRepository applicationStoreRepository,
            IStoreAddressRepository storeAddressRepository,
            IAccountService accountService,
            IAccountInfraService accountInfraService,
            IRoleService roleService)
            : base(context)
        {
            this.storeService               = storeService;
            this.storeRepository            = storeRepository;
            this.applicationRepository      = applicationRepository;
            this.applicationStoreService    = applicationStoreService;
            this.applicationStoreRepository = applicationStoreRepository;
            this.storeAddressRepository     = storeAddressRepository;
            this.accountService             = accountService;

            if (context.TryResolveNamed(FieldType.Store.ToLower(), typeof(IMetadataService), out var metadataService))
            {
                this.metadataService = metadataService as IMetadataService;
            }

            this.accountInfraService = accountInfraService;

            this.roleService = roleService;
        }
Example #2
0
        public bool TryResolve <T>(string serviceName, out T result)
        {
            object localResult;
            var    success = _container.TryResolveNamed(serviceName, typeof(T), out localResult);

            result = (T)localResult;
            return(success);
        }
Example #3
0
        public ICollection <BaseMetadata> SaveValue(IEnumerable <BaseMetadata> metadatas)
        {
            var results = new List <BaseMetadata>();

            metadatas.ForEach(metadata =>
            {
                var field = metadataFieldRepository.GetByJsonId(metadata.Field);

                if (!field.IsNull())
                {
                    metadata.Field = field;

                    metadata.IsValid();

                    if (!field.Validator.IsNull())
                    {
                        MetadataValidator _validatorResult = null;

                        if (context.TryResolveNamed(field.Validator.Type.ToLower(), typeof(IMetadataValidatorService), out var validatorInfraService))
                        {
                            _validatorResult = ((IMetadataValidatorService)validatorInfraService).Get(metadata);
                        }
                        else
                        {
                            _validatorResult = field.Validator;
                        }

                        var valid = _validatorResult.IsValid(metadata);

                        if (!valid)
                        {
                            throw new ArgumentException("Valor informado no campo '{0}' no metadata não é válido para o tipo de validador '{1}'"
                                                        .ToFormat(field.JsonId, field.Validator.Type.GetDescription()));
                        }
                    }

                    BaseMetadata _metadata;

                    var metadataDb = metadataRepository.Get(metadata as T);

                    if (metadataDb.IsNull()) //is new meta
                    {
                        _metadata = metadata.Create();
                    }
                    else
                    {
                        _metadata = metadataDb.Update(metadata);
                    }

                    metadataRepository.Save(_metadata as T);

                    results.Add(_metadata);
                }
            });

            return(results);
        }
Example #4
0
        public T GetInstance <T>(string name) where T : class, IPipelineComponent
        {
            if (_componentContext.TryResolveNamed(name, typeof(T), out var instance))
            {
                return((T)instance);
            }

            throw new PipelineComponentNotFoundException($"Pipeline component named, '{name}' could not be found.");
        }
Example #5
0
        public AccountApplication(
            IComponentContext context,
            IAccountService accountService,
            IAccountRepository accountRepository,
            IEmailSender svcEmail,
            ILockedUpMemberPolicy lockedUpMemberPolicy,
            ILockMemberPolicy lockMemberPolicy,
            IPasswordPolicy passwordPolicy,
            IApplicationStoreRepository applicationStoreRepository,
            IResetPasswordTokenRepository resetPasswordTokenRepository,
            IApplicationRepository applicationRepository,
            IStoreRepository storeRepositoy,
            IAccountRoleRepository accountRoleRepository,
            IRoleRepository roleRepository,
            IPermissionRepository permissionRepository,
            IResourceRepository resourceRepository,
            ICustomerImportService customerImportService,
            IResetPasswordTokenService resetPasswordTokenService,
            IPasswordLogRepository passwordLogRepository,
            IApplicationStoreService applicationStoreService,
            ICustomerRepository customerRepository,
            IAccountPermissionService accPermissionService,
            IAccountInfraService accountInfraService)
            : base(context)
        {
            this.svcEmail                     = svcEmail;
            this.lockedUpMemberPolicy         = lockedUpMemberPolicy;
            this.lockMemberPolicy             = lockMemberPolicy;
            this.passwordPolicy               = passwordPolicy;
            this.accountService               = accountService;
            this.applicationStoreRepository   = applicationStoreRepository;
            this.resetPasswordTokenRepository = resetPasswordTokenRepository;
            this.applicationRepository        = applicationRepository;
            this.storeRepositoy               = storeRepositoy;
            this.accountRoleRepository        = accountRoleRepository;
            this.roleRepository               = roleRepository;
            this.permissionRepository         = permissionRepository;
            this.resourceRepository           = resourceRepository;
            this.passwordLogRepository        = passwordLogRepository;

            this.customerImportService     = customerImportService;
            this.resetPasswordTokenService = resetPasswordTokenService;
            this.applicationStoreService   = applicationStoreService;
            this.accPermissionService      = accPermissionService;

            this.accountRepository  = accountRepository;
            this.customerRepository = customerRepository;

            if (context.TryResolveNamed(FieldType.Account.ToLower(), typeof(IMetadataService), out var metadataService))
            {
                this.metadataService = metadataService as IMetadataService;
            }

            this.accountInfraService = accountInfraService;
        }
Example #6
0
 public virtual object ResolveOptional(Type type, string name = null)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(context.ResolveOptional(type));
     }
     else
     {
         object obj = null;
         context.TryResolveNamed(name, type, out obj);
         return(obj);
     }
 }
Example #7
0
        private object Resolve(Type serviceType, string contract)
        {
            object serviceInstance;

            if (string.IsNullOrEmpty(contract))
            {
                _componentContext.TryResolve(serviceType, out serviceInstance);
            }
            else
            {
                _componentContext.TryResolveNamed(contract, serviceType, out serviceInstance);
            }

            return(serviceInstance);
        }
Example #8
0
        protected override object DoGetInstance(Type serviceType, string key)
        {
            object instance;

            if (string.IsNullOrEmpty(key))
            {
                if (!_container.TryResolve(serviceType, out instance))
                {
                    throw new Exception(string.Format("cannot resolve type {0}", serviceType));
                }
            }
            else
            {
                if (!_container.TryResolveNamed(key, serviceType, out instance))
                {
                    throw new Exception(string.Format("cannot resolve type {0}", serviceType));
                }
            }

            return(instance);
        }
        private object GetInstance(Type service, string key)
        {
            try
            {
                object instance;
                if (string.IsNullOrEmpty(key))
                {
                    if (context.TryResolve(service, out instance))
                    {
                        return(instance);
                    }
                }
                else
                {
                    //caliburn can ask for a Keyed service without providing the type,
                    //to fullfil this we must scan the actual component registry
                    if (service == null)
                    {
                        var unTyped = context.ComponentRegistry.Registrations.SelectMany(
                            x => x.Services.OfType <KeyedService>().Where(y => y.ServiceKey as string == key)).FirstOrDefault();
                        service = unTyped.ServiceType;
                    }

                    if (context.TryResolveNamed(key, service, out instance))
                    {
                        return(instance);
                    }
                }
            }
            catch (Exception ex)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                throw;
            }

            throw new Exception(string.Format("Could not locate any instances of service {0}.", service.Name));
        }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            var tryResolveNamed = _componentContext.TryResolveNamed(binder.Name, typeof(IFeature), out result);

            return(tryResolveNamed);
        }