public Task <SeedingReport> SeedSeeds(SeedBucketStartup seedBucketStartup, params Type[] seedTypes) { // TODO: Checks. Not null, all seeds from the same seed bucket etc, must have seed bucket. // TODO: Workaround so far. Just pick up the first seed bucket. var seedBucketType = seedTypes.First().Assembly.GetTypes().First(type => typeof(SeedBucket).IsAssignableFrom(type)); var filter = new FullNameEqualsSeedableFilter(seedTypes.Select(type => type.FullName).ToArray()); return(SeedSeedBucket(seedBucketType, seedBucketStartup, filter)); }
// TODO: What to return? SeedingReport? How to name the method so that it is clear that it seeds? public async Task <object[]> GetYieldsFor(Type?seedBucketStartupType, params Type[] yieldOfTypes) { // TODO: Checks. All yieldofs, no repeating etc. var result = new object[yieldOfTypes.Length]; // TODO: Get the meta information, check it does not have any errors and out of it the seed types of these yields and seed only those seeds. // TODO: So far just grab the seed bucket and seed it all. var seedBucketType = yieldOfTypes.First().Assembly.GetTypes().First(type => typeof(SeedBucket).IsAssignableFrom(type)); var seedTypes = yieldOfTypes.Select(yieldOfType => yieldOfType.BaseType.GetGenericArguments()[0]); var filter = new FullNameEqualsSeedableFilter(seedTypes.Select(type => type.FullName).ToArray()); var seedingReport = seedBucketStartupType != null ? await SeedSeedBucket(seedBucketType, seedBucketStartupType, filter) : await SeedSeedBucket(seedBucketType, filter); if (seedingReport.Status != SeedingStatus.Succeeded) { throw new Exception(); // TODO: Define how to return data and error status. } // TODO: Brute force so far and a bunch of copy paste. In the production version refactor everything so that the needed objects are there. IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(outputSink); // TODO: Ugly workaround just to quickly get the seed bucket startup type. All this will need a super heavy refactoring one day it goes productive :-) if (seedBucketStartupType is null) { seedBucketStartupType = seedBucketType.Assembly.GetTypes().FirstOrDefault(type => type.IsSeedBucketStartupType()); } if (seedBucketStartupType != null) { var startup = (SeedBucketStartup)ActivatorUtilities.GetServiceOrCreateInstance(serviceCollection.BuildServiceProvider(), seedBucketStartupType); startup.ConfigureServices(serviceCollection); } var serviceProvider = serviceCollection.BuildServiceProvider(); for (var i = 0; i < yieldOfTypes.Length; i++) { var yieldOfType = yieldOfTypes[i]; var yieldingSeed = (ISeed)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, yieldOfType.BaseType.GetGenericArguments()[0]); var yield = ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, yieldOfType); var seedPropertyOnYield = yield.GetType().GetProperty("Seed", BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance); seedPropertyOnYield.SetValue(yield, yieldingSeed); result[i] = yield; } return(result); }