Cache and DbMigrationsConfiguration

Mar 13, 2015 at 4:52 PM
Hello.

We are using DbMigrationsConfiguration, but you use DbConfiguration.
Is it possible to use our configuration with your cache?
Mar 16, 2015 at 5:53 PM
Yes. DbMigrationsConfiguration is a different config - it is only for configuring Migrations while DbConfiguration configures EF in general.

Thanks,
Pawel
Apr 24, 2015 at 9:28 PM
Could you provide with an example please?

I am particularly interested how would you replace DBProviderService with the new CachingProviderService in this case? The Loaded event is not available for this in DbMigrationsConfiguration (EF already loaded by then). Thanks!
Apr 24, 2015 at 9:39 PM
VladKuz wrote:
Could you provide with an example please?

I am particularly interested how would you replace DBProviderService with the new CachingProviderService in this case? The Loaded event is not available for this in DbMigrationsConfiguration (EF already loaded by then). Thanks!
We use app.config
<entityFramework codeConfigurationType="Common.Core.BusinessLayer.BusinessLogic.BusinessEntities.Configuration.CommonConfiguration, Common.Core">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
and class example
 class CommonConfiguration : DbConfiguration
    {
        public CommonConfiguration()
        {
            var transactionHandler = new CacheTransactionHandler(new InMemoryCache());

            AddInterceptor(transactionHandler);

            var fkkoCachingPolicy = new FkkoCachingPolicy();

            Loaded +=
              (sender, args) => args.ReplaceService<DbProviderServices>(
                (s, _) => new CachingProviderServices(s, transactionHandler,
                    fkkoCachingPolicy));
        }
    }
Apr 24, 2015 at 9:46 PM
Thank you for the reply. I use multiple repositories (DDD) with separate DbMigrationsConfiguration for each. I would like to add the caching just for one configuration. I wonder if it's possible without setting it in the common configuration.
Apr 29, 2015 at 5:19 AM
Edited Apr 29, 2015 at 5:19 AM
Cache is registered globally however you can decide what to cache by implementing your own CachingPolicy.