public IFactoryRegistry AddBehavior <TContract, TBehavior>() where TBehavior : TContract
        {
            var supportedBehavior = new SupportedBehavior();

            supportedBehavior.Supports <TContract, TBehavior>();

            _factoryBehaviors[typeof(TContract)] = supportedBehavior;

            return(this);
        }
        public void BehaviorsFor <TDomainEntity>(Action <ISupportedBehavior> entity) where TDomainEntity : IEntityDelegator
        {
            Check.NotNull(entity, nameof(entity));

            var domainEntityType        = typeof(TDomainEntity);
            SupportedBehavior entityReg = null;

            if (!_entityBehaviors.TryGetValue(domainEntityType, out entityReg))
            {
                entityReg = new SupportedBehavior(domainEntityType);
                _entityBehaviors[domainEntityType] = entityReg;
            }

            entity(entityReg);
        }
        private IEnumerable <EntityBehavior> GetBehaviors(Type domainEntityType)
        {
            SupportedBehavior domainEntity = null;

            _entityBehaviors.TryGetValue(domainEntityType, out domainEntity);

            var entityBehaviors = domainEntity != null?domainEntity.SupportedBehaviors.ToList()
                                      : new List <Behavior>();

            // Add any general factory behaviors for which there is not already
            // an entity specific behavior.
            foreach (var factoryBehavior in _factoryBehaviors)
            {
                if (!entityBehaviors.Any(b => b.ContractType == factoryBehavior.Key))
                {
                    entityBehaviors.AddRange(factoryBehavior.Value.SupportedBehaviors);
                }
            }

            return(entityBehaviors.Select(b => new EntityBehavior(b)));
        }