public AuthenticationHelper(IOptions <VicAuthenticationOptions> options, VicContext context, IHttpContextAccessor httpContext)
 {
     _options     = options.Value;
     _salt        = Encoding.UTF8.GetBytes(_options.Salt);
     _context     = context;
     _httpContext = httpContext;
 }
Example #2
0
 /// <summary>
 /// Creates a new instance of a PagesController object, initializes with specified arguments.
 /// </summary>
 /// <param name="context"></param>
 public PagesController(VicContext context)
 {
     _context = context;
 }
 /// <summary>
 /// Creates a new instance of a UsersController object, initializes with specified arguments.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="auth"></param>
 public UsersController(VicContext context, IAuthenticationHelper auth)
 {
     _context = context;
     _auth    = auth;
 }
Example #4
0
 /// <summary>
 /// Creates a new instance of a DataService object, initializes with specified arguments.
 /// </summary>
 /// <param name="fileStation"></param>
 /// <param name="context"></param>
 public DataService(IFileStationApi fileStation, VicContext context)
 {
     _fileStation = fileStation;
     _context     = context;
 }
Example #5
0
        /// <summary>
        /// Applies all of the IEntityTypeConfiguration objects in the specified assembly.
        /// </summary>
        /// <param name="modelBuilder"></param>
        /// <param name="assembly"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static ModelBuilder ApplyAllConfigurations(this ModelBuilder modelBuilder, Assembly assembly, VicContext context = null)
        {
            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            // Find all the configuration classes.
            var type           = typeof(IEntityTypeConfiguration <>);
            var configurations = assembly.GetTypes().Where(t => t.IsClass && t.GetInterfaces().Any(i => i.Name.Equals(type.Name)));

            // Fetch the ApplyConfiguration method so that it can be called on each configuration.
            var method = typeof(ModelBuilder).GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(m => m.Name.Equals(nameof(ModelBuilder.ApplyConfiguration)) && m.GetParameters()[0].ParameterType.GetGenericTypeDefinition() == type).First();

            foreach (var config in configurations)
            {
                if (!config.ContainsGenericParameters)
                {
                    var includeContext           = config.GetConstructors().Any(c => c.GetParameters().Any(p => p.ParameterType == typeof(VicContext)));
                    var entityConfig             = includeContext ? Activator.CreateInstance(config, context) : Activator.CreateInstance(config);
                    var entityType               = config.GetInterfaces().FirstOrDefault().GetGenericArguments()[0];
                    var applyConfigurationMethod = method.MakeGenericMethod(entityType);
                    applyConfigurationMethod.Invoke(modelBuilder, new[] { entityConfig });
                }
            }

            return(modelBuilder);
        }
Example #6
0
 /// <summary>
 /// Applies all of the IEntityTypeConfiguration objects in the assembly of the specified type.
 /// </summary>
 /// <param name="modelBuilder"></param>
 /// <param name="type"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public static ModelBuilder ApplyAllConfigurations(this ModelBuilder modelBuilder, Type type, VicContext context = null)
 {
     if (type == null)
     {
         throw new ArgumentNullException(nameof(type));
     }
     return(modelBuilder.ApplyAllConfigurations(type.Assembly, context));
 }
 /// <summary>
 /// Creates a new instance of a ItemsController object, initializes with specified arguments.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="fileStation"></param>
 /// <param name="serializeOptions"></param>
 public ItemsController(VicContext context, IFileStationApi fileStation, IOptions <JsonSerializerOptions> serializeOptions)
 {
     _context          = context;
     _fileStation      = fileStation;
     _serializeOptions = serializeOptions.Value;
 }
Example #8
0
 /// <summary>
 /// Creates a new instance of a FileStationController object, initializes with specified arguments.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="fileStation"></param>
 public FileStationController(VicContext context, IFileStationApi fileStation)
 {
     _fileStation = fileStation;
     _service     = new DataService(fileStation, context);
 }