Exemplo n.º 1
0
        public static DbContextOptions <TDbContext> Create <TDbContext> (IServiceProvider serviceProvider)
            where TDbContext : RocketDbContext <TDbContext>
        {
            var creationContext = GetCreationContext <TDbContext> (serviceProvider);

            var context = new RocketDbContextConfigurationContext <TDbContext> (
                creationContext.ConnectionString,
                serviceProvider,
                creationContext.ConnectionStringName,
                creationContext.ExistingConnection
                );

            var options = GetDbContextOptions <TDbContext> (serviceProvider);

            PreConfigure(options, context);
            Configure(options, context);

            return(context.DbContextOptions.Options);
        }
Exemplo n.º 2
0
        private static void PreConfigure <TDbContext> (
            RocketDbContextOptions options,
            RocketDbContextConfigurationContext <TDbContext> context)
            where TDbContext : RocketDbContext <TDbContext>
        {
            foreach (var defaultPreConfigureAction in options.DefaultPreConfigureActions)
            {
                defaultPreConfigureAction.Invoke(context);
            }

            var preConfigureActions = options.PreConfigureActions.GetOrDefault(typeof(TDbContext));

            if (!preConfigureActions.IsNullOrEmpty())
            {
                foreach (var preConfigureAction in preConfigureActions)
                {
                    ((Action <RocketDbContextConfigurationContext <TDbContext> >)preConfigureAction).Invoke(context);
                }
            }
        }
Exemplo n.º 3
0
        private static void Configure <TDbContext> (
            RocketDbContextOptions options,
            RocketDbContextConfigurationContext <TDbContext> context)
            where TDbContext : RocketDbContext <TDbContext>
        {
            var configureAction = options.ConfigureActions.GetOrDefault(typeof(TDbContext));

            if (configureAction != null)
            {
                ((Action <RocketDbContextConfigurationContext <TDbContext> >)configureAction).Invoke(context);
            }
            else if (options.DefaultConfigureAction != null)
            {
                options.DefaultConfigureAction.Invoke(context);
            }
            else
            {
                throw new RocketException(
                          $"No configuration found for {typeof(DbContext).AssemblyQualifiedName}! Use services.Configure<RocketDbContextOptions>(...) to configure it.");
            }
        }
 public void Configure(RocketDbContextConfigurationContext context)
 {
     Action.Invoke(context);
 }