private void CreateAccessor() { var nodeConfiguration = new NodeConfiguration(); var configuration = DomainConfigurationFactory.Create(); var descriptor = ProviderDescriptor.Get(configuration.ConnectionInfo.Provider); var driverFactory = (SqlDriverFactory)Activator.CreateInstance(descriptor.DriverFactory); var storageDriver = StorageDriver.Create(driverFactory, configuration); var nameBuilder = new NameBuilder(configuration, storageDriver.ProviderInfo); var handlerFactory = (HandlerFactory)Activator.CreateInstance(descriptor.HandlerFactory); var accessor = new UpgradeServiceAccessor { Configuration = configuration, StorageDriver = storageDriver, NameBuilder = nameBuilder, HandlerFactory = handlerFactory }; configuration.Lock(); var connection = storageDriver.CreateConnection(null); connection.Open(); accessor.MappingResolver = MappingResolver.Create(configuration, nodeConfiguration, storageDriver.GetDefaultSchema(connection)); if (storageDriver.ProviderInfo.Supports(ProviderFeatures.SingleConnection)) { accessor.RegisterTemporaryResource(connection); } else { accessor.RegisterResource(connection); } accessor.Connection = connection; accessor.Connection.Extensions.AddOne(new TypeDelegator(typeof(IProviderExecutor))); this.accessor = accessor; }
private void BuildExternalServices(UpgradeServiceAccessor serviceAccessor, UpgradeContext context) { var configuration = context.Configuration; var standardRegistrations = new[] { new ServiceRegistration(typeof(DomainConfiguration), context.Configuration), new ServiceRegistration(typeof(UpgradeContext), context) }; var modules = configuration.Types.Modules .Select(type => new ServiceRegistration(typeof(IModule), type, false)); var handlers = configuration.Types.UpgradeHandlers .Select(type => new ServiceRegistration(typeof(IUpgradeHandler), type, false)); var registrations = standardRegistrations.Concat(modules).Concat(handlers); var serviceContainer = new ServiceContainer(registrations); serviceAccessor.RegisterResource(serviceContainer); BuildModules(serviceAccessor, serviceContainer); BuildUpgradeHandlers(serviceAccessor, serviceContainer); }