/// <summary> /// Builds the required services and an <see cref="ICakeHost" /> using the specified options. /// </summary> /// <returns>The built <see cref="ICakeHost" />.</returns> public ICakeHost Build() { try { // Create the "base" container with the minimum // stuff registered to run Cake at all. var registrar = new CakeServices(); registrar.RegisterModule(new CoreModule()); registrar.RegisterModule(new Module()); var container = registrar.Build(); // Add custom registrations to the container. container.Update(_registrations); // Find and register tasks with the container. RegisterTasks(container); // Resolve the application and run it. return(container.Resolve <ICakeHost>()); } catch (Exception exception) { return(new ErrorCakeHost(exception)); } }
private static void RegisterTasks(Container container) { // Create a child scope to not affect the underlying // container in case the ICakeTaskFinder references // something that is later replaced. using (var scope = container.CreateChildScope()) { // Find tasks in registered assemblies. var assemblies = scope.Resolve <IEnumerable <Assembly> >(); var finder = scope.Resolve <ICakeTaskFinder>(); var tasks = finder.GetTasks(assemblies); if (tasks.Length > 0) { var registrar = new CakeServices(); foreach (var task in tasks) { registrar.RegisterType(task).As <IFrostingTask>().Singleton(); } container.Update(registrar); } } }
/// <summary> /// Initializes a new instance of the <see cref="CakeHostBuilder"/> class. /// </summary> public CakeHostBuilder() { _registrations = new CakeServices(); }