protected override void Load(ContainerBuilder builder) { // when you resolve a process, you need to add a cfg parameter builder.Register((c, p) => { var context = c.Resolve <IContext>(p); var response = p.TypedAs <Response>(); return(new ReverseConfiguration(context, response).Create()); }).Named <Process>("page").InstancePerLifetimeScope(); builder.Register <IRunTimeRun>((c, p) => { var context = c.Resolve <IContext>(p); var process = c.ResolveNamed <Process>("page", p); var container = DefaultContainer.Create(process, c.Resolve <IPipelineLogger>()); return(new RunTimeRunner( context, container )); } ).As <IRunTimeRun>(); builder.Register((c, p) => { var process = c.ResolveNamed <Process>("page", p); var runner = c.Resolve <IRunTimeRun>(); return(new Pager(process, runner)); }).As <Pager>(); }
protected override void Load(ContainerBuilder builder) { // an input connection builder.Register((c, p) => c.Resolve <Cfg>(p).Input()).As <Connection>(); // an input connection context builder.Register <IConnectionContext>((c, p) => new ConnectionContext(c.Resolve <IContext>(p), c.Resolve <Connection>())).As <IConnectionContext>(); // a schema reader for file or excel builder.Register <ISchemaReader>((c, p) => { var context = c.Resolve <IConnectionContext>(); var connection = c.Resolve <Connection>(); var fileInfo = new FileInfo(Path.IsPathRooted(connection.File) ? connection.File : Path.Combine(AppDomain.CurrentDomain.BaseDirectory, connection.File)); var cfg = context.Connection.Provider == "file" ? new FileInspection(context, fileInfo).Create() : new ExcelInspection(context, fileInfo).Create(); var process = c.Resolve <Process>(p.Concat(new[] { new NamedParameter("cfg", cfg) })); process.Pipeline = "parallel.linq"; var container = DefaultContainer.Create(process, c.Resolve <IPipelineLogger>()); return(new SchemaReader(context, new RunTimeRunner(context, container), process)); }).As <ISchemaReader>(); builder.Register <IRunTimeExecute>((c, p) => new RunTimeExecutor(c.Resolve <IConnectionContext>())).As <IRunTimeExecute>(); // when you resolve a process, you need to add a cfg parameter builder.Register((c, p) => { var parameters = new List <global::Autofac.Core.Parameter>(); parameters.AddRange(p); var cfg = new ConfigurationCreator(c.Resolve <Cfg>(p), c.Resolve <ISchemaReader>(p)).Create(); parameters.Add(new NamedParameter("cfg", cfg)); return(c.Resolve <Process>(parameters)); }).Named <Process>("import"); // Connection Factory builder.Register <IConnectionFactory>(c => { var output = c.Resolve <Cfg>().Output(); switch (output.Provider) { case "sqlserver": return(new SqlServerConnectionFactory(output)); case "mysql": return(new MySqlConnectionFactory(output)); case "postgresql": return(new PostgreSqlConnectionFactory(output)); case "sqlce": return(new SqlCeConnectionFactory(output)); case "sqlite": return(new SqLiteConnectionFactory(output)); case "access": return(new AccessConnectionFactory(output)); default: return(new NullConnectionFactory()); } }).As <IConnectionFactory>().InstancePerLifetimeScope(); // Final product is Importer builder.Register((c, p) => { var context = c.Resolve <IConnectionContext>(); var request = c.Resolve <Request>(p); var key = request.ToKey(c.Resolve <Cfg>()); var process = c.Resolve <Process>(); if (Cache.ContainsKey(key)) { process.Load(Cache[key]); context.Info("Using cached delimiter, header, type, and string-length inspection."); } else { process = c.ResolveNamed <Process>("import", p); Cache[key] = process.Serialize(); context.Info("Cached delimiter, header, type, and string-length inspection."); } return(new Importer(process, c.Resolve <IRunTimeExecute>(p), c.Resolve <IConnectionFactory>())); }).As <Importer>(); }