Exemple #1
0
        public void Initialize(bool dslAspects)
        {
            using (var inner = ObjectFactory.CreateInnerFactory())
            {
                inner.RegisterType(typeof(AspectConfiguration));
                var aspectConfiguration = inner.Resolve <AspectConfiguration>();
                aspectConfiguration.Configure();

                if (dslAspects)
                {
                    inner.RegisterTypes(aspectConfiguration.DslAspects);
                    foreach (var type in aspectConfiguration.DslAspects)
                    {
                        var asp = inner.Resolve <IDslAspect>(type);
                        asp.Register(AspectRegistrator);
                    }
                }
                inner.RegisterTypes(aspectConfiguration.SystemAspects);
                foreach (var type in aspectConfiguration.SystemAspects)
                {
                    var asp = inner.Resolve <ISystemAspect>(type);
                    asp.Initialize(ObjectFactory);
                }
            }
        }
        private void CheckPermissions()
        {
            if (!PermissionsChanged)
            {
                return;
            }
            using (var scope = ObjectFactory.CreateInnerFactory())
            {
                var globals = scope.Resolve <IQueryable <IGlobalPermission> >();
                var roles   = scope.Resolve <IQueryable <IRolePermission> >();

                GlobalPermissions =
                    globals.ToList()
                    .ToDictionary(it => it.Name, it => it.IsAllowed);
                RolePermissions =
                    (from dop in roles.ToList()
                     group dop by dop.Name into g
                     let values = g.Select(it => new Pair {
                    Name = it.RoleID, IsAllowed = it.IsAllowed
                })
                                  select new { g.Key, values })
                    .ToDictionary(it => it.Key, it => it.values.ToList());
            }
            Cache = new Dictionary <string, bool>();
            PermissionsChanged = false;
        }
 public UnitOfWork(IObjectFactory factory)
 {
     Scope         = factory.CreateInnerFactory();
     Manager       = factory.Resolve <IDatabaseQueryManager>();
     DatabaseQuery = Manager.BeginTransaction();
     Scope.RegisterInstance(DatabaseQuery);
     Context = Scope.Resolve <IDataContext>();
 }
Exemple #4
0
        public ProcessingEngine(
            IObjectFactory objectFactory,
            IScopePool scopePool,
            IPermissionManager permissions,
            IExtensibilityProvider extensibilityProvider)
        {
            Contract.Requires(objectFactory != null);
            Contract.Requires(scopePool != null);
            Contract.Requires(permissions != null);
            Contract.Requires(extensibilityProvider != null);

            this.ObjectFactory = objectFactory.CreateInnerFactory();
            this.ScopePool     = scopePool;
            this.Permissions   = permissions;
            var commandTypes = extensibilityProvider.FindPlugins <IServerCommand>();

            var commands = new Dictionary <Type, Type>();

            foreach (var ct in commandTypes)
            {
                commands[ct] = ct;
            }
            foreach (var ct in commandTypes)
            {
                var attr = ct.GetCustomAttributes(typeof(ExportMetadataAttribute), false) as ExportMetadataAttribute[];
                if (attr != null)
                {
                    var insteadOf = attr.FirstOrDefault(it => it.Name == Metadata.InsteadOf);
                    if (insteadOf != null)
                    {
                        var type = insteadOf.Value as Type;
                        if (commandTypes.All(it => it != type))
                        {
                            throw new FrameworkException("Can't find target {0} for InsteadOf attribute declared on {1}".With(type, ct));
                        }
                        commands[type] = ct;
                    }
                }
            }
            foreach (var ct in commands)
            {
                ActualCommands[ct.Key] = ObjectFactory.Resolve <IServerCommand>(ct.Value);
            }
        }
Exemple #5
0
        public ProcessingEngine(
            IObjectFactory objectFactory,
            IDatabaseQueryManager transactionManager,
            IPermissionManager permissions,
            ILogFactory logFactory,
            IExtensibilityProvider extensibilityProvider)
        {
            Contract.Requires(objectFactory != null);
            Contract.Requires(transactionManager != null);
            Contract.Requires(permissions != null);
            Contract.Requires(logFactory != null);
            Contract.Requires(extensibilityProvider != null);

            this.ObjectFactory      = objectFactory.CreateInnerFactory();
            this.TransactionManager = transactionManager;
            this.Permissions        = permissions;
            this.Logger             = logFactory.Create("Processing engine");
            var commandTypes = extensibilityProvider.FindPlugins <IServerCommand>();

            ObjectFactory.RegisterTypes(commandTypes, InstanceScope.Transient);
            foreach (var ct in commandTypes)
            {
                ActualCommands[ct] = ct;
            }
            foreach (var ct in commandTypes)
            {
                var attr = ct.GetCustomAttributes(typeof(ExportMetadataAttribute), false) as ExportMetadataAttribute[];
                if (attr != null)
                {
                    var insteadOf = attr.FirstOrDefault(it => it.Name == Metadata.InsteadOf);
                    if (insteadOf != null)
                    {
                        var type = insteadOf.Value as Type;
                        if (commandTypes.All(it => it != type))
                        {
                            throw new FrameworkException("Can't find target {0} for InsteadOf attribute declared on {1}".With(type, ct));
                        }
                        ActualCommands[type] = ct;
                    }
                }
            }
        }