Ejemplo n.º 1
0
        private object GetContext(int contextId, EntitySecurityConfiguration entitySecurityConfiguration)
        {
            var repository = (IEntityRepository)this.dependencyInjectionContainer.GetInstance(entitySecurityConfiguration.Repository);
            var context    = repository.Find(contextId);

            return(context);
        }
        /// <summary>
        /// Scans assembly for <see cref="IPermissionManager{TUserAction,TUser,TContext}"/> and adds keeps
        /// the result for future reference.
        /// </summary>
        /// <param name="assembly"></param>
        public void RegisterAssembly(Assembly assembly)
        {
            var permissionManagers = assembly.ExportedTypes
                                     .Where(t =>
            {
                var typeInfo = t.GetTypeInfo();

                return(typeInfo.IsClass &&
                       !typeInfo.IsAbstract &&
                       !typeInfo.IsGenericType);
            })
                                     .Where(t => t.GetTypeInfo().GetInterfaces()
                                            .Any(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(IPermissionManager <, ,>)))
                                     .ToList();

            foreach (var permissionManager in permissionManagers)
            {
                var guard = new EntitySecurityConfiguration(permissionManager);
                this.Guards.TryAdd(guard.ContextType, guard);
            }

            var repositories = assembly.ExportedTypes
                               .Where(t =>
            {
                var typeInfo = t.GetTypeInfo();

                return(typeInfo.IsClass &&
                       !typeInfo.IsAbstract &&
                       !typeInfo.IsGenericType);
            })
                               .Where(t => t.GetTypeInfo().GetInterfaces().Any(i => i == typeof(IEntityRepository)))
                               .ToList();

            foreach (var repository in repositories)
            {
                this.RegisterRepository(repository);
            }
        }