├── .github ├── FUNDING.yml ├── workflows │ ├── merge.yml │ ├── docs.yml │ ├── stale.yml │ └── dotnet.yml └── dependabot.yml ├── docs ├── db │ ├── mongoDB.md │ ├── mySql.md │ ├── sqlite.md │ ├── sqlServer.md │ ├── postgreSQL.md │ └── database.md ├── di │ ├── ninject.md │ ├── unity.md │ ├── autofac.md │ ├── simpleInjector.md │ ├── registration.md │ └── dependencyInjection.md ├── automapper.md ├── mongoDB.md ├── startup.md ├── configuration.md ├── index.md └── usage.md ├── logo.png ├── test ├── Test.Core │ ├── SampleWorker.cs │ ├── Status.cs │ ├── IUserRepository.cs │ ├── IEmployeeRepository.cs │ ├── IUserService.cs │ ├── ContactType.cs │ ├── EmailAddress.cs │ ├── PhoneNumber.cs │ ├── IService.cs │ ├── IReadOnlyRepository.cs │ ├── IRepository.cs │ ├── OrderLine.cs │ ├── IConnection.cs │ ├── User.cs │ ├── Startup │ │ └── TestStartup.cs │ ├── Employee.cs │ ├── IVehicle.cs │ ├── Test.Core.csproj │ ├── Order.cs │ ├── UserRepository.cs │ ├── EmployeeRepository.cs │ ├── UserService.cs │ ├── Contact.cs │ ├── MailingAddress.cs │ └── UserServiceModule.cs ├── KickStart.Tests │ ├── xunit.runner.json │ ├── StartupTask │ │ ├── HighTask.cs │ │ ├── MediumCTask.cs │ │ ├── MediumATask.cs │ │ └── MediumBTask.cs │ ├── AssemblyExtensionsTest.cs │ ├── App.config │ ├── KickStart.Tests.csproj │ ├── Services │ │ └── ConcreteTypeFilterTest.cs │ └── AssemblyResolverTest.cs ├── KickStart.Autofac.Tests │ ├── xunit.runner.json │ ├── UserModule.cs │ └── KickStart.Autofac.Tests.csproj ├── KickStart.MongoDB.Tests │ ├── xunit.runner.json │ ├── KickStart.MongoDB.Tests.csproj │ ├── UserMap.cs │ └── MongoStarterTest.cs ├── KickStart.Ninject.Tests │ ├── xunit.runner.json │ ├── UserNinjectModule.cs │ ├── KickStart.Ninject.Tests.csproj │ └── NinjectStarterTest.cs ├── KickStart.Unity.Tests │ ├── xunit.runner.json │ ├── UserUnityRegistration.cs │ ├── UserServiceModule.cs │ ├── KickStart.Unity.Tests.csproj │ └── UnityStarterTest.cs ├── KickStart.AutoMapper.Tests │ ├── xunit.runner.json │ ├── UserProfile.cs │ ├── KickStart.AutoMapper.Tests.csproj │ └── AutoMapperKickerTest.cs ├── KickStart.EntityChange.Tests │ ├── xunit.runner.json │ ├── OrderProfile.cs │ ├── KickStart.EntityChange.Tests.csproj │ └── EntityCompareTests.cs ├── KickStart.SimpleInjector.Tests │ ├── xunit.runner.json │ ├── UserSimpleInjectorRegistration.cs │ ├── InjectorStartTask.cs │ └── KickStart.SimpleInjector.Tests.csproj ├── KickStart.DependencyInjection.Tests │ ├── xunit.runner.json │ ├── UserDependencyInjectionRegistration.cs │ ├── KickStart.DependencyInjection.Tests.csproj │ └── DependencyInjectionrStarterTest.cs └── Directory.Build.props ├── src ├── KickStart.MongoDB │ ├── IMongoBuilder.cs │ ├── MongoOptions.cs │ ├── KickStart.MongoDB.csproj │ ├── MongoBuilder.cs │ ├── MongoExtensions.cs │ └── MongoStarter.cs ├── KickStart │ ├── KickStart.csproj │ ├── IKickStarter.cs │ ├── StartupTask │ │ ├── StartupTaskOptions.cs │ │ ├── IStartupTaskBuilder.cs │ │ ├── IStartupTask.cs │ │ ├── StartupTaskBuilder.cs │ │ ├── StartupTaskBase.cs │ │ ├── StartupTaskExtensions.cs │ │ └── StartupTaskStarter.cs │ ├── Services │ │ ├── IServiceModule.cs │ │ ├── ServiceLifetime.cs │ │ ├── TypeMap.cs │ │ ├── IServiceRegistrationBuilder.cs │ │ ├── IServiceRegistration.cs │ │ ├── IServiceTypeMapper.cs │ │ ├── ServiceRegistrationBuilder.cs │ │ ├── IConcreteTypeFilter.cs │ │ ├── ServiceRegistrationBase.cs │ │ └── ServiceProviderExtensions.cs │ ├── Configuration.cs │ └── Kick.cs ├── KickStart.Unity │ ├── IUnityRegistration.cs │ ├── IUnityBuilder.cs │ ├── UnityOptions.cs │ ├── KickStart.Unity.csproj │ ├── UnityBuilder.cs │ ├── UnityServiceProvider.cs │ ├── UnityExtensions.cs │ ├── UnityStarter.cs │ └── UnityServiceRegistration.cs ├── KickStart.Serilog │ ├── ISerilogConfiguration.cs │ ├── SerilogOptions.cs │ ├── KickStart.Serilog.csproj │ ├── SerilogStarter.cs │ └── SerilogExtensions.cs ├── KickStart.NLog │ ├── KickStart.NLog.csproj │ └── NLogExtensions.cs ├── KickStart.Log4Net │ ├── KickStart.Log4Net.csproj │ └── Log4NetExtensions.cs ├── KickStart.Autofac │ ├── KickStart.Autofac.csproj │ ├── IAutofacBuilder.cs │ ├── AutofacOptions.cs │ ├── AutofacServiceProvider.cs │ ├── AutofacExtensions.cs │ ├── AutofacBuilder.cs │ ├── AutofacStarter.cs │ └── AutofacServiceRegistration.cs ├── KickStart.EntityChange │ ├── EntityChangeOptions.cs │ ├── KickStart.EntityChange.csproj │ ├── IEntityChangeBuilder.cs │ ├── EntityChangeBuilder.cs │ ├── EntityChangeStarter.cs │ └── EntityChangeExtensions.cs ├── KickStart.Ninject │ ├── KickStart.Ninject.csproj │ ├── NinjectOptions.cs │ ├── INinjectBuilder.cs │ ├── NinjectBuilder.cs │ ├── NinjectStarter.cs │ └── NinjectExtensions.cs ├── KickStart.AutoMapper │ ├── KickStart.AutoMapper.csproj │ ├── AutoMapperOptions.cs │ ├── IAutoMapperBuilder.cs │ ├── AutoMapperServiceModule.cs │ ├── AutoMapperStarter.cs │ ├── AutoMapperBuilder.cs │ └── AutoMapperExtensions.cs ├── KickStart.SimpleInjector │ ├── ISimpleInjectorRegistration.cs │ ├── KickStart.SimpleInjector.csproj │ ├── ISimpleInjectorBuilder.cs │ ├── SimpleInjectorOptions.cs │ ├── SimpleInjectorExtensions.cs │ ├── SimpleInjectorBuilder.cs │ ├── SimpleInjectorStarter.cs │ └── SimpleInjectorRegistration.cs ├── KickStart.DependencyInjection │ ├── IDependencyInjectionRegistration.cs │ ├── KickStart.DependencyInjection.csproj │ ├── IDependencyInjectionBuilder.cs │ ├── DependencyInjectionOptions.cs │ ├── ServiceCollectionExtensions.cs │ ├── DependencyInjectionBuilder.cs │ ├── DependencyInjectionStarter.cs │ ├── DependencyInjectionExtensions.cs │ └── DependencyInjectionRegistration.cs └── Directory.Build.props ├── coverlet.runsettings ├── mkdocs.yml ├── LICENSE ├── .editorconfig ├── Directory.Packages.props ├── KickStart.slnx └── .gitattributes /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: loresoft 2 | -------------------------------------------------------------------------------- /docs/db/mongoDB.md: -------------------------------------------------------------------------------- 1 | MongoDB Script Deployment -------------------------------------------------------------------------------- /docs/db/mySql.md: -------------------------------------------------------------------------------- 1 | MySql Script Deployment -------------------------------------------------------------------------------- /docs/db/sqlite.md: -------------------------------------------------------------------------------- 1 | Sqlite Script Deployment -------------------------------------------------------------------------------- /docs/db/sqlServer.md: -------------------------------------------------------------------------------- 1 | Sql Server Script Deployment -------------------------------------------------------------------------------- /docs/di/ninject.md: -------------------------------------------------------------------------------- 1 | Ninject Dependency Injection -------------------------------------------------------------------------------- /docs/db/postgreSQL.md: -------------------------------------------------------------------------------- 1 | PostgreSQL Script Deployment -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/loresoft/KickStart/HEAD/logo.png -------------------------------------------------------------------------------- /docs/automapper.md: -------------------------------------------------------------------------------- 1 | # AutoMapper Startup Task 2 | 3 | Registers all AutoMapper `Profile` classes. -------------------------------------------------------------------------------- /test/Test.Core/SampleWorker.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public class SampleWorker 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /docs/mongoDB.md: -------------------------------------------------------------------------------- 1 | # MongoDB Startup Task 2 | 3 | Registers all `BsonClassMap` classes with MongoDB serialization -------------------------------------------------------------------------------- /test/Test.Core/Status.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public enum Status 4 | { 5 | New, 6 | Verified 7 | } -------------------------------------------------------------------------------- /test/Test.Core/IUserRepository.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public interface IUserRepository : IRepository 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /test/Test.Core/IEmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public interface IEmployeeRepository : IRepository 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /test/KickStart.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeAssembly": false, 4 | "parallelizeTestCollections": false 5 | } -------------------------------------------------------------------------------- /test/KickStart.Autofac.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeAssembly": false, 4 | "parallelizeTestCollections": false 5 | } -------------------------------------------------------------------------------- /test/KickStart.MongoDB.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeAssembly": false, 4 | "parallelizeTestCollections": false 5 | } -------------------------------------------------------------------------------- /test/KickStart.Ninject.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeAssembly": false, 4 | "parallelizeTestCollections": false 5 | } -------------------------------------------------------------------------------- /test/KickStart.Unity.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeAssembly": false, 4 | "parallelizeTestCollections": false 5 | } -------------------------------------------------------------------------------- /test/Test.Core/IUserService.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public interface IUserService : IRepository 4 | { 5 | IConnection Connection { get; } 6 | } -------------------------------------------------------------------------------- /test/KickStart.AutoMapper.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeAssembly": false, 4 | "parallelizeTestCollections": false 5 | } -------------------------------------------------------------------------------- /test/KickStart.EntityChange.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeAssembly": false, 4 | "parallelizeTestCollections": false 5 | } -------------------------------------------------------------------------------- /test/KickStart.SimpleInjector.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeAssembly": false, 4 | "parallelizeTestCollections": false 5 | } -------------------------------------------------------------------------------- /test/KickStart.DependencyInjection.Tests/xunit.runner.json: -------------------------------------------------------------------------------- 1 | { 2 | "maxParallelThreads": 1, 3 | "parallelizeAssembly": false, 4 | "parallelizeTestCollections": false 5 | } -------------------------------------------------------------------------------- /test/Test.Core/ContactType.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public enum ContactType 4 | { 5 | Home, 6 | Business, 7 | Personal, 8 | Mobile 9 | 10 | } -------------------------------------------------------------------------------- /test/Test.Core/EmailAddress.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public class EmailAddress 4 | { 5 | public ContactType Type { get; set; } 6 | public string Address { get; set; } 7 | } -------------------------------------------------------------------------------- /test/Test.Core/PhoneNumber.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public class PhoneNumber 4 | { 5 | public ContactType Type { get; set; } 6 | public string Number { get; set; } 7 | } -------------------------------------------------------------------------------- /src/KickStart.MongoDB/IMongoBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.MongoDB; 2 | 3 | /// 4 | /// MongoDB builder interface 5 | /// 6 | public interface IMongoBuilder 7 | { 8 | } -------------------------------------------------------------------------------- /src/KickStart/KickStart.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netstandard2.0;net8.0 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /test/Test.Core/IService.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public interface IService { } 4 | 5 | public class Service1 : IService { } 6 | 7 | public class Service2 : IService { } 8 | 9 | public class Service3 : IService { } -------------------------------------------------------------------------------- /src/KickStart.MongoDB/MongoOptions.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.MongoDB; 2 | 3 | /// 4 | /// KickStart MongoDB options class 5 | /// 6 | public class MongoOptions 7 | { 8 | // placeholder, no options yet 9 | } -------------------------------------------------------------------------------- /test/Test.Core/IReadOnlyRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace Test.Core; 4 | 5 | public interface IReadOnlyRepository 6 | { 7 | TEntity Get(Expression> filter); 8 | ICollection GetAll(); 9 | } -------------------------------------------------------------------------------- /test/Test.Core/IRepository.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public interface IRepository : IReadOnlyRepository 4 | { 5 | TEntity Add(TEntity entity); 6 | 7 | bool Update(TEntity entity); 8 | 9 | bool Delete(TEntity entity); 10 | } -------------------------------------------------------------------------------- /test/Test.Core/OrderLine.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public class OrderLine 4 | { 5 | public string Sku { get; set; } 6 | 7 | public string Description { get; set; } 8 | 9 | public int Quanity { get; set; } 10 | 11 | public decimal UnitPrice { get; set; } 12 | } -------------------------------------------------------------------------------- /test/Test.Core/IConnection.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public interface IConnection 4 | { 5 | void Open(); 6 | } 7 | 8 | 9 | public class SampleConnection : IConnection 10 | { 11 | public void Open() 12 | { 13 | throw new NotImplementedException(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/Test.Core/User.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public class User 4 | { 5 | public string Id { get; set; } 6 | public string FirstName { get; set; } 7 | public string LastName { get; set; } 8 | public string EmailAddress { get; set; } 9 | public byte[] SysVersion { get; set; } 10 | } -------------------------------------------------------------------------------- /test/Test.Core/Startup/TestStartup.cs: -------------------------------------------------------------------------------- 1 | using KickStart.StartupTask; 2 | 3 | namespace Test.Core.Startup; 4 | 5 | public class TestStartup : StartupTaskBase 6 | { 7 | public override void Run(IDictionary data) 8 | { 9 | Console.WriteLine("Run Test Startup Test"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/Test.Core/Employee.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public class Employee 4 | { 5 | public string Id { get; set; } 6 | public string FirstName { get; set; } 7 | public string LastName { get; set; } 8 | public string EmailAddress { get; set; } 9 | public byte[] SysVersion { get; set; } 10 | 11 | } -------------------------------------------------------------------------------- /test/KickStart.AutoMapper.Tests/UserProfile.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.AutoMapper.Tests; 6 | 7 | public class UserProfile : Profile 8 | { 9 | public UserProfile() 10 | { 11 | CreateMap(); 12 | CreateMap(); 13 | } 14 | } -------------------------------------------------------------------------------- /test/KickStart.Ninject.Tests/UserNinjectModule.cs: -------------------------------------------------------------------------------- 1 | using Ninject.Modules; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.Ninject.Tests; 6 | 7 | public class UserNinjectModule : NinjectModule 8 | { 9 | public override void Load() 10 | { 11 | Bind().To(); 12 | } 13 | } -------------------------------------------------------------------------------- /test/Test.Core/IVehicle.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public interface IVehicle { } 4 | 5 | public interface ICar : IVehicle { } 6 | 7 | public interface ITruck : IVehicle { } 8 | 9 | public interface IVan : IVehicle { } 10 | 11 | public interface IMinivan : IVan { } 12 | 13 | public class DeliveryVehicle : IMinivan, ICar, ITruck { } -------------------------------------------------------------------------------- /test/KickStart.Autofac.Tests/UserModule.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.Autofac.Tests; 6 | 7 | public class UserModule : Module 8 | { 9 | protected override void Load(ContainerBuilder builder) 10 | { 11 | builder.RegisterType().As(); 12 | 13 | } 14 | } -------------------------------------------------------------------------------- /test/KickStart.Tests/StartupTask/HighTask.cs: -------------------------------------------------------------------------------- 1 | using KickStart.StartupTask; 2 | 3 | namespace KickStart.Tests.StartupTask; 4 | 5 | public class HighTask : IStartupTask 6 | { 7 | public int Priority => 10; 8 | 9 | public Task RunAsync(IDictionary data) 10 | { 11 | return Task.Delay(1000); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/KickStart.Tests/StartupTask/MediumCTask.cs: -------------------------------------------------------------------------------- 1 | using KickStart.StartupTask; 2 | 3 | namespace KickStart.Tests.StartupTask; 4 | 5 | public class MediumCTask : IStartupTask 6 | { 7 | public int Priority => 100; 8 | 9 | public Task RunAsync(IDictionary data) 10 | { 11 | return Task.Delay(100); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/KickStart.Tests/StartupTask/MediumATask.cs: -------------------------------------------------------------------------------- 1 | using KickStart.StartupTask; 2 | 3 | namespace KickStart.Tests.StartupTask; 4 | 5 | public class MediumATask : IStartupTask 6 | { 7 | public int Priority => 100; 8 | 9 | public Task RunAsync(IDictionary data) 10 | { 11 | return Task.Delay(1000); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/KickStart.Unity.Tests/UserUnityRegistration.cs: -------------------------------------------------------------------------------- 1 | using Test.Core; 2 | 3 | using Unity; 4 | 5 | namespace KickStart.Unity.Tests; 6 | 7 | public class UserUnityRegistration : IUnityRegistration 8 | { 9 | public void Register(IUnityContainer container) 10 | { 11 | container.RegisterType(); 12 | } 13 | } -------------------------------------------------------------------------------- /test/KickStart.Tests/StartupTask/MediumBTask.cs: -------------------------------------------------------------------------------- 1 | using KickStart.StartupTask; 2 | 3 | namespace KickStart.Tests.StartupTask; 4 | 5 | public class MediumBTask : IStartupTask 6 | { 7 | public int Priority => 100; 8 | 9 | public Task RunAsync(IDictionary data) 10 | { 11 | return Task.Delay(1100); 12 | } 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/Test.Core/Test.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /coverlet.runsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | lcov 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/KickStart.Unity/IUnityRegistration.cs: -------------------------------------------------------------------------------- 1 | using Unity; 2 | 3 | namespace KickStart.Unity; 4 | 5 | 6 | /// 7 | /// Unity container registration interface 8 | /// 9 | public interface IUnityRegistration 10 | { 11 | /// 12 | /// Registers the specified container. 13 | /// 14 | /// The container. 15 | void Register(IUnityContainer container); 16 | } -------------------------------------------------------------------------------- /src/KickStart.Serilog/ISerilogConfiguration.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | 3 | namespace KickStart; 4 | 5 | /// 6 | /// Serilog Configuration interface 7 | /// 8 | public interface ISerilogConfiguration 9 | { 10 | /// 11 | /// Configure Serilog configuration options 12 | /// 13 | /// The Serilog configuration to update 14 | void Configure(LoggerConfiguration configuration); 15 | } -------------------------------------------------------------------------------- /test/KickStart.Unity.Tests/UserServiceModule.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.Unity.Tests; 6 | 7 | public class UserServiceModule : IServiceModule 8 | { 9 | public void Register(IServiceRegistration services, IDictionary data) 10 | { 11 | services.RegisterSingleton(); 12 | services.RegisterTransient(); 13 | } 14 | } -------------------------------------------------------------------------------- /test/Test.Core/Order.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public class Order 4 | { 5 | public string Id { get; set; } 6 | 7 | public int OrderNumber { get; set; } 8 | 9 | public Contact Contact { get; set; } 10 | 11 | public MailingAddress ShippingAddress { get; set; } 12 | 13 | public MailingAddress BillingAddress { get; set; } 14 | 15 | public List Items { get; set; } 16 | 17 | public decimal Total { get; set; } 18 | } 19 | -------------------------------------------------------------------------------- /docs/di/unity.md: -------------------------------------------------------------------------------- 1 | # Unity 2 | 3 | The Unity extension allows registration of types to be resolved by running all instances of `IUnityRegistration`. 4 | 5 | Basic usage 6 | 7 | ```csharp 8 | Kick.Start(config => config 9 | .IncludeAssemblyFor() // where to look 10 | .UseUnity () // initialize Unity 11 | ); 12 | ``` 13 | 14 | To install Unity extension, run the following command in the Package Manager Console 15 | 16 | PM> Install-Package KickStart.Unity -------------------------------------------------------------------------------- /test/KickStart.SimpleInjector.Tests/UserSimpleInjectorRegistration.cs: -------------------------------------------------------------------------------- 1 | using SimpleInjector; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.SimpleInjector.Tests; 6 | 7 | public class UserSimpleInjectorRegistration : ISimpleInjectorRegistration 8 | { 9 | public void Register(Container container, IDictionary data) 10 | { 11 | container.Register(); 12 | container.Register(); 13 | } 14 | } -------------------------------------------------------------------------------- /test/KickStart.DependencyInjection.Tests/UserDependencyInjectionRegistration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.DependencyInjection.Tests; 6 | 7 | public class UserDependencyInjectionRegistration : IDependencyInjectionRegistration 8 | { 9 | public void Register(IServiceCollection services, IDictionary data) 10 | { 11 | services.AddTransient(); 12 | } 13 | } -------------------------------------------------------------------------------- /test/KickStart.Tests/AssemblyExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | using Test.Core; 2 | 3 | namespace KickStart.Tests; 4 | 5 | public class AssemblyExtensionsTest 6 | { 7 | [Fact] 8 | public void IsAssignableTo() 9 | { 10 | var result = typeof(IVehicle).IsAssignableTo(typeof(DeliveryVehicle)); 11 | result.Should().BeFalse(); 12 | 13 | 14 | result = typeof(DeliveryVehicle).IsAssignableTo(typeof(IVehicle)); 15 | result.Should().BeTrue(); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/KickStart/IKickStarter.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart; 2 | 3 | /// 4 | /// An that defines an application KickStart extension 5 | /// 6 | public interface IKickStarter 7 | { 8 | /// 9 | /// Runs the application KickStart extension with specified . 10 | /// 11 | /// The KickStart containing assemblies to scan. 12 | void Run(Context context); 13 | } -------------------------------------------------------------------------------- /src/KickStart.Unity/IUnityBuilder.cs: -------------------------------------------------------------------------------- 1 | using Unity; 2 | 3 | namespace KickStart.Unity; 4 | 5 | 6 | /// 7 | /// Unity builder interface 8 | /// 9 | public interface IUnityBuilder 10 | { 11 | /// 12 | /// Sets the initialize container . 13 | /// 14 | /// The initializer the container. 15 | /// 16 | IUnityBuilder Container(Action initializer); 17 | 18 | } -------------------------------------------------------------------------------- /src/KickStart.Unity/UnityOptions.cs: -------------------------------------------------------------------------------- 1 | using Unity; 2 | 3 | namespace KickStart.Unity; 4 | 5 | /// 6 | /// Unity configuration options 7 | /// 8 | public class UnityOptions 9 | { 10 | /// 11 | /// Gets or sets the initialize container . 12 | /// 13 | /// 14 | /// The initialize container . 15 | /// 16 | public Action InitializeContainer { get; set; } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /test/KickStart.Tests/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/KickStart.Serilog/SerilogOptions.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | 3 | namespace KickStart; 4 | 5 | /// 6 | /// Options for Serilog 7 | /// 8 | public class SerilogOptions 9 | { 10 | /// 11 | /// Gets or sets the to call for additional configuration. 12 | /// 13 | /// 14 | /// The to call for additional configuration. 15 | /// 16 | public Action Configure { get; set; } 17 | } -------------------------------------------------------------------------------- /src/KickStart/StartupTask/StartupTaskOptions.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.StartupTask; 2 | 3 | /// 4 | /// Startup tasks options class 5 | /// 6 | public class StartupTaskOptions 7 | { 8 | /// 9 | /// Gets the startup actions. 10 | /// 11 | /// 12 | /// The startup actions. 13 | /// 14 | public IList>> Actions { get; } = new List>>(); 15 | } -------------------------------------------------------------------------------- /test/KickStart.EntityChange.Tests/OrderProfile.cs: -------------------------------------------------------------------------------- 1 | using EntityChange; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.EntityChange.Tests; 6 | 7 | public class OrderProfile : EntityProfile 8 | { 9 | public override void Configure() 10 | { 11 | Property(p => p.Total).Formatter(v => v.ToString("c")); 12 | 13 | Collection(p => p.Items).ElementFormatter(v => 14 | { 15 | var orderLine = v as OrderLine; 16 | return orderLine?.Sku; 17 | }); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/KickStart.NLog/KickStart.NLog.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides NLog integration for KickStart, enabling flexible logging and startup configuration for .NET applications. 4 | net472;netstandard2.0;net8.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/KickStart.Log4Net/KickStart.Log4Net.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides log4net integration for KickStart, enabling flexible logging and startup configuration for .NET applications. 4 | net472;netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/KickStart.Serilog/KickStart.Serilog.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides Serilog integration for KickStart, enabling flexible logging and startup configuration for .NET applications. 4 | netstandard2.0;net8.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/KickStart.Unity/KickStart.Unity.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides Unity integration for KickStart, enabling streamlined dependency injection and startup configuration for .NET applications. 4 | net472;netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/KickStart.Autofac/KickStart.Autofac.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides Autofac integration for KickStart, enabling streamlined dependency injection and startup configuration for .NET applications. 4 | netstandard2.0;net8.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/KickStart.EntityChange/EntityChangeOptions.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.EntityChange; 2 | 3 | /// 4 | /// KickStart EntityChange options. 5 | /// 6 | public class EntityChangeOptions 7 | { 8 | /// 9 | /// Gets or sets the to call for additional configuration. 10 | /// 11 | /// 12 | /// The to call for additional configuration. 13 | /// 14 | public Action Configure { get; set; } 15 | } -------------------------------------------------------------------------------- /src/KickStart.Ninject/KickStart.Ninject.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides Ninject integration for KickStart, enabling flexible dependency injection and startup configuration for .NET applications. 4 | net472;netstandard2.0;net6.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/KickStart.AutoMapper/KickStart.AutoMapper.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides AutoMapper integration for KickStart, enabling streamlined object mapping and startup configuration for .NET applications. 4 | net8.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/KickStart.MongoDB/KickStart.MongoDB.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides MongoDB integration for KickStart, enabling efficient database connectivity and startup configuration for .NET applications. 4 | net472;netstandard2.1;net8.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/KickStart.EntityChange/KickStart.EntityChange.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides EntityChange integration for KickStart, enabling efficient entity change tracking and startup configuration for .NET applications. 4 | netstandard2.0;net8.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/KickStart.SimpleInjector/ISimpleInjectorRegistration.cs: -------------------------------------------------------------------------------- 1 | using SimpleInjector; 2 | 3 | namespace KickStart.SimpleInjector; 4 | 5 | /// 6 | /// SimpleInjector registration module 7 | /// 8 | public interface ISimpleInjectorRegistration 9 | { 10 | /// 11 | /// Register injections with the specified container. 12 | /// 13 | /// The container. 14 | /// The data dictionary shared with all starter modules. 15 | void Register(Container container, IDictionary data); 16 | } -------------------------------------------------------------------------------- /src/KickStart.SimpleInjector/KickStart.SimpleInjector.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides SimpleInjector integration for KickStart, enabling streamlined dependency injection and startup configuration for .NET applications. 4 | net472;netstandard2.0;netstandard2.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/KickStart.SimpleInjector.Tests/InjectorStartTask.cs: -------------------------------------------------------------------------------- 1 | using KickStart.StartupTask; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.SimpleInjector.Tests; 6 | 7 | public class InjectorStartTask : StartupTaskBase 8 | { 9 | private readonly IUserService _userService; 10 | 11 | public InjectorStartTask(IUserService userService) 12 | { 13 | _userService = userService; 14 | } 15 | 16 | public override void Run(IDictionary data) 17 | { 18 | _userService.Should().NotBeNull(); 19 | _userService.Connection.Should().NotBeNull(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/KickStart/StartupTask/IStartupTaskBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.StartupTask; 2 | 3 | /// 4 | /// A fluent to configure startup tasks 5 | /// 6 | public interface IStartupTaskBuilder 7 | { 8 | /// 9 | /// Runs the specified startup action. 10 | /// 11 | /// The startup action. 12 | /// 13 | /// A fluent to configure startup tasks 14 | /// 15 | IStartupTaskBuilder Run(Action> startupAction); 16 | } -------------------------------------------------------------------------------- /test/KickStart.Unity.Tests/KickStart.Unity.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/KickStart/Services/IServiceModule.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// Service registration module 5 | /// 6 | public interface IServiceModule 7 | { 8 | /// 9 | /// Register service injections with the specified container. 10 | /// 11 | /// The container to add the module services to. 12 | /// The data dictionary shared with all starter modules. 13 | void Register(IServiceRegistration services, IDictionary data); 14 | } -------------------------------------------------------------------------------- /test/KickStart.Autofac.Tests/KickStart.Autofac.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/KickStart.MongoDB.Tests/KickStart.MongoDB.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/KickStart.MongoDB.Tests/UserMap.cs: -------------------------------------------------------------------------------- 1 | using MongoDB.Bson; 2 | using MongoDB.Bson.Serialization; 3 | using MongoDB.Bson.Serialization.IdGenerators; 4 | using MongoDB.Bson.Serialization.Serializers; 5 | 6 | using Test.Core; 7 | 8 | namespace KickStart.MongoDB.Tests; 9 | 10 | public class UserMap : BsonClassMap 11 | { 12 | public UserMap() 13 | { 14 | AutoMap(); 15 | 16 | var idMember = GetMemberMap(p => p.Id) 17 | .SetSerializer(new StringSerializer(BsonType.ObjectId)) 18 | .SetIdGenerator(StringObjectIdGenerator.Instance); 19 | 20 | SetIdMember(idMember); 21 | } 22 | } -------------------------------------------------------------------------------- /test/KickStart.Ninject.Tests/KickStart.Ninject.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/Test.Core/UserRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace Test.Core; 4 | 5 | public class UserRepository : IUserRepository 6 | { 7 | public User Add(User entity) 8 | { 9 | return null; 10 | } 11 | 12 | public bool Update(User entity) 13 | { 14 | return false; 15 | } 16 | 17 | public bool Delete(User entity) 18 | { 19 | return false; 20 | } 21 | 22 | public User Get(Expression> filter) 23 | { 24 | return null; 25 | } 26 | 27 | public ICollection GetAll() 28 | { 29 | return null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/KickStart.Tests/KickStart.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/KickStart.AutoMapper.Tests/KickStart.AutoMapper.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/KickStart.EntityChange.Tests/KickStart.EntityChange.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/KickStart.Ninject/NinjectOptions.cs: -------------------------------------------------------------------------------- 1 | using Ninject; 2 | 3 | namespace KickStart.Ninject; 4 | 5 | /// 6 | /// Ninject options 7 | /// 8 | public class NinjectOptions 9 | { 10 | /// 11 | /// Gets or sets the settings. 12 | /// 13 | /// 14 | /// The settings. 15 | /// 16 | public INinjectSettings Settings { get; set; } 17 | /// 18 | /// Gets or sets the initialize kernel delegate. 19 | /// 20 | /// 21 | /// The initialize kernel delegate. 22 | /// 23 | public Action InitializeKernel { get; set; } 24 | } -------------------------------------------------------------------------------- /test/KickStart.SimpleInjector.Tests/KickStart.SimpleInjector.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/Test.Core/EmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace Test.Core; 4 | 5 | public class EmployeeRepository : IEmployeeRepository 6 | { 7 | public Employee Add(Employee entity) 8 | { 9 | return null; 10 | } 11 | 12 | public bool Update(Employee entity) 13 | { 14 | return false; 15 | } 16 | 17 | public bool Delete(Employee entity) 18 | { 19 | return false; 20 | } 21 | 22 | public Employee Get(Expression> filter) 23 | { 24 | return null; 25 | } 26 | 27 | public ICollection GetAll() 28 | { 29 | return null; 30 | } 31 | } -------------------------------------------------------------------------------- /test/KickStart.DependencyInjection.Tests/KickStart.DependencyInjection.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | PreserveNewest 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/KickStart/Services/ServiceLifetime.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// Specifies the lifetime of a service in an . 5 | /// 6 | public enum ServiceLifetime 7 | { 8 | /// 9 | /// Specifies that a single instance of the service will be created. 10 | /// 11 | Singleton, 12 | /// 13 | /// Specifies that a new instance of the service will be created for each scope. 14 | /// 15 | Scoped, 16 | /// 17 | /// Specifies that a new instance of the service will be created every time it is requested. 18 | /// 19 | Transient 20 | } -------------------------------------------------------------------------------- /.github/workflows/merge.yml: -------------------------------------------------------------------------------- 1 | name: Dependabot Auto-Merge 2 | on: pull_request 3 | 4 | permissions: 5 | contents: write 6 | pull-requests: write 7 | 8 | jobs: 9 | dependabot: 10 | runs-on: ubuntu-latest 11 | if: github.actor == 'dependabot[bot]' 12 | 13 | steps: 14 | - name: Dependabot Metadata 15 | id: metadata 16 | uses: dependabot/fetch-metadata@v2 17 | with: 18 | github-token: "${{ secrets.GITHUB_TOKEN }}" 19 | 20 | - name: Dependabot Auto-Merge PRs 21 | run: gh pr merge --auto --merge "$PR_URL" 22 | env: 23 | PR_URL: ${{github.event.pull_request.html_url}} 24 | GH_TOKEN: ${{secrets.GITHUB_TOKEN}} 25 | -------------------------------------------------------------------------------- /src/KickStart.DependencyInjection/IDependencyInjectionRegistration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | 4 | namespace KickStart.DependencyInjection; 5 | 6 | /// 7 | /// Microsoft.Extensions.DependencyInjection registration module 8 | /// 9 | public interface IDependencyInjectionRegistration 10 | { 11 | /// 12 | /// Register injections with the specified IServiceCollection. 13 | /// 14 | /// The services collection. 15 | /// The data dictionary shared with all starter modules. 16 | void Register(IServiceCollection services, IDictionary data); 17 | } 18 | -------------------------------------------------------------------------------- /src/KickStart.EntityChange/IEntityChangeBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.EntityChange; 2 | 3 | /// 4 | /// Fluent builder. 5 | /// 6 | public interface IEntityChangeBuilder 7 | { 8 | /// 9 | /// Passes the current to add additional configuration options. 10 | /// 11 | /// The delegate to call for additional configuration. 12 | /// 13 | /// Fluent builder. 14 | /// 15 | IEntityChangeBuilder Configure(Action configuration); 16 | } -------------------------------------------------------------------------------- /src/KickStart.DependencyInjection/KickStart.DependencyInjection.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Provides integration with Microsoft.Extensions.DependencyInjection for KickStart, enabling streamlined dependency injection and startup configuration for .NET applications. 4 | netstandard2.0;net8.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/KickStart.Ninject/INinjectBuilder.cs: -------------------------------------------------------------------------------- 1 | using Ninject; 2 | 3 | namespace KickStart.Ninject; 4 | 5 | /// 6 | /// Ninject fluent builder 7 | /// 8 | public interface INinjectBuilder 9 | { 10 | /// 11 | /// Set the specified Ninject settings. 12 | /// 13 | /// The Ninjectsettings. 14 | /// 15 | INinjectBuilder Settings(INinjectSettings settings); 16 | /// 17 | /// Set the specified initializer. 18 | /// 19 | /// The initializer. 20 | /// 21 | INinjectBuilder Kernal(Action initializer); 22 | } -------------------------------------------------------------------------------- /src/KickStart/StartupTask/IStartupTask.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.StartupTask; 2 | 3 | /// 4 | /// Interface defining a task that should run on application startup 5 | /// 6 | public interface IStartupTask 7 | { 8 | /// 9 | /// Gets the priority of this task. Lower numbers run first. 10 | /// 11 | /// 12 | /// The priority of this task. 13 | /// 14 | int Priority { get; } 15 | 16 | /// 17 | /// Runs the startup task with the specified context asynchronously. 18 | /// 19 | /// The data dictionary shared with all starter modules. 20 | Task RunAsync(IDictionary data); 21 | } 22 | -------------------------------------------------------------------------------- /src/KickStart.MongoDB/MongoBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.MongoDB; 2 | 3 | /// 4 | /// MongoDB fluent builder 5 | /// 6 | /// 7 | public class MongoBuilder : IMongoBuilder 8 | { 9 | /// 10 | /// Gets the MongoDB configuration options. 11 | /// 12 | /// 13 | /// The MongoDB configuration options.. 14 | /// 15 | public MongoOptions Options { get; } 16 | 17 | /// 18 | /// Initializes a new instance of the class. 19 | /// 20 | /// The options. 21 | public MongoBuilder(MongoOptions options) 22 | { 23 | Options = options; 24 | } 25 | } -------------------------------------------------------------------------------- /test/Test.Core/UserService.cs: -------------------------------------------------------------------------------- 1 | using System.Linq.Expressions; 2 | 3 | namespace Test.Core; 4 | 5 | public class UserService : IUserService 6 | { 7 | 8 | public IConnection Connection { get; } 9 | 10 | public UserService(IConnection connection) 11 | { 12 | Connection = connection; 13 | } 14 | 15 | 16 | public User Add(User entity) 17 | { 18 | return null; 19 | } 20 | 21 | public bool Update(User entity) 22 | { 23 | return false; 24 | } 25 | 26 | public bool Delete(User entity) 27 | { 28 | return false; 29 | } 30 | 31 | public User Get(Expression> filter) 32 | { 33 | return null; 34 | } 35 | 36 | public ICollection GetAll() 37 | { 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /docs/startup.md: -------------------------------------------------------------------------------- 1 | # Startup Task 2 | 3 | The StartupTask extension allows running code on application start-up. To use this extension, implement the `IStartupTask` interface. Use the `Priority` property to control the order of execution. 4 | 5 | Basic usage 6 | 7 | ```csharp 8 | Kick.Start(config => config 9 | .IncludeAssemblyFor() // where to look for tasks 10 | .UseStartupTask() // include startup tasks in the Kick Start 11 | ); 12 | ``` 13 | 14 | Run a delegate on startup 15 | 16 | ```csharp 17 | Kick.Start(config => config 18 | .IncludeAssemblyFor() 19 | .UseAutofac() // init Autofac or any other IoC as container 20 | .UseStartupTask(c => c => 21 | { 22 | c.Run((services, data) => 23 | { 24 | //do work here 25 | }); 26 | }) 27 | ); 28 | ``` -------------------------------------------------------------------------------- /src/KickStart.AutoMapper/AutoMapperOptions.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | 3 | namespace KickStart.AutoMapper; 4 | 5 | /// 6 | /// KickStart AutoMapper options. 7 | /// 8 | public class AutoMapperOptions 9 | { 10 | /// 11 | /// Gets or sets a value indicating whether to validate AutoMapper. 12 | /// 13 | /// 14 | /// true to validate; otherwise, false. 15 | /// 16 | public bool Validate { get; set; } 17 | 18 | /// 19 | /// Gets or sets the to call for additional configuration. 20 | /// 21 | /// 22 | /// The to call for additional configuration. 23 | /// 24 | public Action Initialize { get; set; } 25 | } -------------------------------------------------------------------------------- /test/Test.Core/Contact.cs: -------------------------------------------------------------------------------- 1 | namespace Test.Core; 2 | 3 | public class Contact 4 | { 5 | public string Id { get; set; } 6 | 7 | public string FirstName { get; set; } 8 | 9 | public string MiddleName { get; set; } 10 | 11 | public string LastName { get; set; } 12 | 13 | public string JobTitle { get; set; } 14 | 15 | public Status Status { get; set; } 16 | 17 | public bool IsActive { get; set; } 18 | 19 | public string[] Roles { get; set; } 20 | 21 | public DateTime Created { get; set; } 22 | 23 | public DateTime Updated { get; set; } 24 | 25 | public List MailingAddresses { get; set; } 26 | 27 | public List EmailAddresses { get; set; } 28 | 29 | public List PhoneNumbers { get; set; } 30 | 31 | public HashSet Categories { get; set; } 32 | 33 | public Dictionary Data { get; set; } 34 | } -------------------------------------------------------------------------------- /docs/di/autofac.md: -------------------------------------------------------------------------------- 1 | # Autofac 2 | 3 | The Autofac extension allows registration of types to be resolved. 4 | 5 | Basic usage 6 | 7 | ```csharp 8 | Kick.Start(config => config 9 | .IncludeAssemblyFor() // where to look for tasks 10 | .UseAutofac() // initialize Autofac 11 | ); 12 | ``` 13 | 14 | Use with ASP.NET MVC 15 | 16 | ```csharp 17 | Kick.Start(c => c 18 | .IncludeAssemblyFor() 19 | .UseAutofac(a => a 20 | .Initialize(b => b.RegisterControllers(typeof(MvcApplication).Assembly)) // register all controllers 21 | .Container(r => DependencyResolver.SetResolver(new AutofacDependencyResolver(r))) // set asp.net resolver 22 | ) 23 | .UseAutoMapper() 24 | .UseMongoDB() 25 | .UseStartupTask() 26 | ); 27 | ``` 28 | 29 | 30 | To install Autofac extension, run the following command in the Package Manager Console 31 | 32 | PM> Install-Package KickStart.Autofac -------------------------------------------------------------------------------- /test/KickStart.MongoDB.Tests/MongoStarterTest.cs: -------------------------------------------------------------------------------- 1 | using MongoDB.Bson.Serialization; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.MongoDB.Tests; 6 | 7 | public class MongoStarterTest 8 | { 9 | private readonly ITestOutputHelper _output; 10 | 11 | public MongoStarterTest(ITestOutputHelper output) 12 | { 13 | _output = output; 14 | } 15 | 16 | [Fact] 17 | public void Configure() 18 | { 19 | Kick.Start(config => config 20 | .LogTo(_output.WriteLine) 21 | .IncludeAssemblyFor() 22 | .UseMongoDB() 23 | ); 24 | 25 | var isMapped = BsonClassMap.IsClassMapRegistered(typeof(User)); 26 | isMapped.Should().BeTrue(); 27 | 28 | var map = BsonClassMap.LookupClassMap(typeof(User)); 29 | map.Should().NotBeNull(); 30 | map.IdMemberMap.Should().NotBeNull(); 31 | map.IdMemberMap.MemberName.Should().Be("Id"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/Test.Core/MailingAddress.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace Test.Core; 4 | 5 | public class MailingAddress 6 | { 7 | public ContactType Type { get; set; } 8 | public string Address1 { get; set; } 9 | public string Address2 { get; set; } 10 | public string Address3 { get; set; } 11 | public string City { get; set; } 12 | public string State { get; set; } 13 | public string Zip { get; set; } 14 | 15 | 16 | public override string ToString() 17 | { 18 | var b = new StringBuilder(); 19 | if (Address1 != null) 20 | b.Append(Address1) 21 | .Append(", "); 22 | 23 | if (City != null) 24 | b.Append(City) 25 | .Append(", "); 26 | 27 | 28 | if (State != null) 29 | b.Append(State) 30 | .Append(" "); 31 | 32 | if (Zip != null) 33 | b.Append(Zip); 34 | 35 | return b.ToString(); 36 | } 37 | } -------------------------------------------------------------------------------- /src/KickStart.Unity/UnityBuilder.cs: -------------------------------------------------------------------------------- 1 | using Unity; 2 | 3 | namespace KickStart.Unity; 4 | 5 | /// 6 | /// Unity fluent builder 7 | /// 8 | /// 9 | public class UnityBuilder : IUnityBuilder 10 | { 11 | private readonly UnityOptions _options; 12 | 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The options. 17 | public UnityBuilder(UnityOptions options) 18 | { 19 | _options = options; 20 | } 21 | 22 | /// 23 | /// Sets the initialize container . 24 | /// 25 | /// The initializer the container. 26 | /// 27 | public IUnityBuilder Container(Action initializer) 28 | { 29 | _options.InitializeContainer = initializer; 30 | return this; 31 | } 32 | } -------------------------------------------------------------------------------- /src/KickStart/Services/TypeMap.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// Implementation to service type mapping 5 | /// 6 | public struct TypeMap 7 | { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | /// The implementation type 12 | /// The service types 13 | public TypeMap(Type implementationType, IEnumerable serviceTypes) 14 | { 15 | ImplementationType = implementationType ?? throw new ArgumentNullException(nameof(implementationType)); 16 | ServiceTypes = serviceTypes ?? throw new ArgumentNullException(nameof(serviceTypes)); 17 | } 18 | 19 | /// 20 | /// Gets the implementation type 21 | /// 22 | public Type ImplementationType { get; } 23 | 24 | /// 25 | ///Gets the service types 26 | /// 27 | public IEnumerable ServiceTypes { get; } 28 | } -------------------------------------------------------------------------------- /test/Test.Core/UserServiceModule.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | namespace Test.Core; 4 | 5 | public class UserServiceModule : IServiceModule 6 | { 7 | public void Register(IServiceRegistration services, IDictionary data) 8 | { 9 | services.RegisterSingleton(); 10 | services.RegisterTransient(c => new UserService(c.GetService())); 11 | 12 | 13 | services.RegisterSingleton(r => r 14 | .Types(t => t.AssignableTo(typeof(IReadOnlyRepository<>))) 15 | .As(s => s.Self().ImplementedInterfaces()) 16 | ); 17 | 18 | services.RegisterSingleton(r => r 19 | .Types(t => t.AssignableTo()) 20 | .As(s => s.Self().ImplementedInterfaces()) 21 | ); 22 | 23 | services.RegisterSingleton(r => r 24 | .Types(t => t.AssignableTo()) 25 | .As(s => s.Self().ImplementedInterfaces()) 26 | ); 27 | 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /test/KickStart.Ninject.Tests/NinjectStarterTest.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | using Ninject; 4 | 5 | using Test.Core; 6 | 7 | namespace KickStart.Ninject.Tests; 8 | 9 | public class NinjectStarterTest 10 | { 11 | private readonly ITestOutputHelper _output; 12 | 13 | public NinjectStarterTest(ITestOutputHelper output) 14 | { 15 | _output = output; 16 | } 17 | 18 | [Fact] 19 | public void UseNinject() 20 | { 21 | Kick.Start(config => config 22 | .LogTo(_output.WriteLine) 23 | .IncludeAssemblyFor() 24 | .UseNinject() 25 | ); 26 | 27 | Kick.ServiceProvider.Should().NotBeNull(); 28 | Kick.ServiceProvider.Should().BeOfType(); 29 | Kick.ServiceProvider.As().Should().BeOfType(); 30 | 31 | var repo = Kick.ServiceProvider.GetService(); 32 | repo.Should().NotBeNull(); 33 | repo.Should().BeOfType(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/KickStart.MongoDB/MongoExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart.MongoDB; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace KickStart; 5 | 6 | /// 7 | /// KickStart Extension for MongoDB. 8 | /// 9 | public static class MongoExtensions 10 | { 11 | /// 12 | /// Use the KickStart extension to configure MongoDB. 13 | /// 14 | /// The configuration builder. 15 | /// 16 | /// A fluent to configure KickStart. 17 | /// 18 | public static IConfigurationBuilder UseMongoDB(this IConfigurationBuilder configurationBuilder) 19 | { 20 | var options = new MongoOptions(); 21 | var starter = new MongoStarter(options); 22 | 23 | configurationBuilder.ExcludeAssemblyFor(); 24 | configurationBuilder.ExcludeAssemblyFor(); 25 | configurationBuilder.Use(starter); 26 | 27 | return configurationBuilder; 28 | } 29 | } -------------------------------------------------------------------------------- /src/KickStart/StartupTask/StartupTaskBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.StartupTask; 2 | 3 | /// 4 | /// A fluent to configure startup tasks 5 | /// 6 | public class StartupTaskBuilder : IStartupTaskBuilder 7 | { 8 | private readonly StartupTaskOptions _options; 9 | 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The options. 14 | public StartupTaskBuilder(StartupTaskOptions options) 15 | { 16 | _options = options; 17 | } 18 | 19 | /// 20 | /// Runs the specified startup action. 21 | /// 22 | /// The startup action. 23 | /// 24 | /// A fluent to configure startup tasks 25 | /// 26 | public IStartupTaskBuilder Run(Action> startupAction) 27 | { 28 | _options.Actions.Add(startupAction); 29 | return this; 30 | } 31 | } -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: KickStart 2 | theme: material 3 | repo_url: https://github.com/loresoft/KickStart 4 | 5 | nav: 6 | - Home: index.md 7 | 8 | - Configuration: configuration.md 9 | - Usage: usage.md 10 | 11 | - Startup Task: startup.md 12 | - AutoMapper: automapper.md 13 | - MongoDB: mongoDB.md 14 | 15 | - Dependency Injection: 16 | - Generic Registration: di/registration.md 17 | - Autofac: di/autofac.md 18 | - DependencyInjection: di/dependencyInjection.md 19 | - Ninject: di/ninject.md 20 | - SimpleInjector: di/simpleInjector.md 21 | - Unity: di/unity.md 22 | 23 | - Database Deployment: 24 | - Usage: db/database.md 25 | - Sql Server: db/sqlServer.md 26 | - PostgreSQL: db/postgreSQL.md 27 | - MySql: db/mySql.md 28 | - Sqlite: db/sqlite.md 29 | - MongoDB: db/mongoDB.md 30 | 31 | markdown_extensions: 32 | - tables 33 | - pymdownx.highlight: 34 | anchor_linenums: true 35 | line_spans: __span 36 | pygments_lang_class: true 37 | - pymdownx.inlinehilite 38 | - pymdownx.snippets 39 | - pymdownx.superfences 40 | -------------------------------------------------------------------------------- /src/KickStart.Unity/UnityServiceProvider.cs: -------------------------------------------------------------------------------- 1 | using Unity; 2 | 3 | namespace KickStart.Unity; 4 | 5 | /// 6 | /// Unity adaptor for 7 | /// 8 | public class UnityServiceProvider : IServiceProvider 9 | { 10 | private readonly IUnityContainer _container; 11 | 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// The container. 16 | public UnityServiceProvider(IUnityContainer container) 17 | { 18 | _container = container; 19 | } 20 | 21 | /// 22 | /// Gets the service object of the specified type 23 | /// 24 | /// An object that specifies the type of service object to get. 25 | /// 26 | /// A service object of type serviceType.-or- null if there is no service object of type serviceType. 27 | /// 28 | public object GetService(Type serviceType) 29 | { 30 | return _container.Resolve(serviceType); 31 | } 32 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 LoreSoft 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/KickStart.AutoMapper/IAutoMapperBuilder.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | 3 | namespace KickStart.AutoMapper; 4 | 5 | /// 6 | /// Fluent builder. 7 | /// 8 | public interface IAutoMapperBuilder 9 | { 10 | /// 11 | /// Call after configuration to validate the state of the mapping. 12 | /// 13 | /// if set to true to call to validate. 14 | /// 15 | /// Fluent builder. 16 | /// 17 | IAutoMapperBuilder Validate(bool value = true); 18 | 19 | /// 20 | /// Passes the current to add additional configuration options. 21 | /// 22 | /// The delegate to call for additional configuration. 23 | /// 24 | /// Fluent builder. 25 | /// 26 | IAutoMapperBuilder Initialize(Action configuration); 27 | } -------------------------------------------------------------------------------- /docs/db/database.md: -------------------------------------------------------------------------------- 1 | Database deployment script processing 2 | 3 | 4 | ```csharp 5 | Kick.Start(c => c 6 | .IncludeAssemblyFor() 7 | .UseDatabase(d => d 8 | .Scripts(s => s 9 | .Embedded(e => e 10 | .StartsWith("Script") 11 | .Contains("Scripts") 12 | ) 13 | .Directory(path) 14 | .Script() 15 | ) 16 | .SqlServer(s => s 17 | .Connection(connectionString) 18 | .Transaction(None|PerScript|Full) 19 | .Journal(table, schema) 20 | ) 21 | .PostgreSQL(s => s 22 | .Connection(connectionString) 23 | .Transaction(None|PerScript|Full) 24 | .Journal(table, schema) 25 | ) 26 | .MySql(s => s 27 | .Connection(connectionString) 28 | .Transaction(None|PerScript|Full) 29 | .Journal(table, schema) 30 | ) 31 | .SQLite(s => s 32 | .Connection(connectionString) 33 | .Transaction(None|PerScript|Full) 34 | .Journal(table) 35 | ) 36 | ) 37 | ); 38 | 39 | 40 | ``` -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig: https://EditorConfig.org 2 | 3 | root = true 4 | 5 | # All Files 6 | [*] 7 | charset = utf-8 8 | indent_style = space 9 | indent_size = 4 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | # XML Configuration Files 14 | [*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct,refactorlog,runsettings}] 15 | indent_size = 2 16 | 17 | # JSON Files 18 | [*.{json,json5,webmanifest}] 19 | indent_size = 2 20 | 21 | # Project Files 22 | [*.{csproj,sqlproj}] 23 | indent_size = 2 24 | 25 | # YAML Files 26 | [*.{yml,yaml}] 27 | indent_size = 2 28 | 29 | # Markdown Files 30 | [*.md] 31 | trim_trailing_whitespace = false 32 | 33 | # Web Files 34 | [*.{htm,html,js,jsm,ts,tsx,css,sass,scss,less,pcss,svg,vue}] 35 | indent_size = 2 36 | 37 | # Batch Files 38 | [*.{cmd,bat}] 39 | end_of_line = crlf 40 | 41 | # Bash Files 42 | [*.sh] 43 | end_of_line = lf 44 | 45 | [*.{cs,vb}] 46 | dotnet_sort_system_directives_first = true 47 | dotnet_separate_import_directive_groups = true 48 | dotnet_style_namespace_match_folder = true 49 | 50 | [*.cs] 51 | csharp_using_directive_placement = outside_namespace 52 | csharp_style_namespace_declarations = file_scoped:warning -------------------------------------------------------------------------------- /src/KickStart.EntityChange/EntityChangeBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.EntityChange; 2 | 3 | /// 4 | /// Fluent builder. 5 | /// 6 | public class EntityChangeBuilder : IEntityChangeBuilder 7 | { 8 | private readonly EntityChangeOptions _options; 9 | 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The EntityChangeOptions to configure. 14 | public EntityChangeBuilder(EntityChangeOptions options) 15 | { 16 | _options = options; 17 | } 18 | 19 | /// 20 | /// Passes the current to add additional configuration options. 21 | /// 22 | /// The delegate to call for additional configuration. 23 | /// 24 | /// Fluent builder. 25 | /// 26 | public IEntityChangeBuilder Configure(Action configuration) 27 | { 28 | _options.Configure = configuration; 29 | return this; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /test/KickStart.Tests/Services/ConcreteTypeFilterTest.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | using KickStart.Services; 4 | 5 | using Test.Core; 6 | 7 | namespace KickStart.Tests.Services; 8 | 9 | public class ConcreteTypeFilterTest 10 | { 11 | [Fact] 12 | public void AssignableToVehicle() 13 | { 14 | var types = typeof(IVehicle).GetTypeInfo().Assembly.GetLoadableTypes().ToList(); 15 | types.Should().NotBeEmpty(); 16 | 17 | var filter = new ConcreteTypeFilter(types); 18 | filter.AssignableTo(typeof(IVehicle)); 19 | 20 | var filteredTypes = filter.FilteredTypes.ToList(); 21 | filteredTypes.Should().NotBeEmpty(); 22 | filteredTypes.Count.Should().Be(1); 23 | } 24 | 25 | [Fact] 26 | public void AssignableToService() 27 | { 28 | var types = typeof(IService).GetTypeInfo().Assembly.GetLoadableTypes().ToList(); 29 | types.Should().NotBeEmpty(); 30 | 31 | var filter = new ConcreteTypeFilter(types); 32 | filter.AssignableTo(typeof(IService)); 33 | 34 | var filteredTypes = filter.FilteredTypes.ToList(); 35 | filteredTypes.Should().NotBeEmpty(); 36 | filteredTypes.Count.Should().Be(3); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/KickStart.Autofac/IAutofacBuilder.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Builder; 3 | 4 | namespace KickStart.Autofac; 5 | 6 | /// 7 | /// Autofac builder interface 8 | /// 9 | public interface IAutofacBuilder 10 | { 11 | /// 12 | /// Sets Autofac build options. 13 | /// 14 | /// The build options. 15 | /// 16 | IAutofacBuilder Options(ContainerBuildOptions buildOptions); 17 | 18 | /// 19 | /// Sets the initialize builder . Register services under this . 20 | /// 21 | /// The initialize builder . 22 | /// 23 | IAutofacBuilder Initialize(Action initializer); 24 | 25 | /// 26 | /// Sets the container accessor . Resolve services under this . 27 | /// 28 | /// The container accessor . 29 | /// 30 | IAutofacBuilder Container(Action accessor); 31 | } -------------------------------------------------------------------------------- /src/KickStart.AutoMapper/AutoMapperServiceModule.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | 3 | using KickStart.Services; 4 | 5 | namespace KickStart.AutoMapper; 6 | 7 | 8 | /// 9 | /// AutoMapper service module registration 10 | /// 11 | /// 12 | public class AutoMapperServiceModule : IServiceModule 13 | { 14 | /// Register service injections with the specified container. 15 | /// The container to add the module services to. 16 | /// The data dictionary shared with all starter modules. 17 | public void Register(IServiceRegistration services, IDictionary data) 18 | { 19 | data.TryGetValue(AutoMapperStarter.AutoMapperConfiguration, out var configurationValue); 20 | 21 | var configuration = configurationValue as IConfigurationProvider; 22 | if (configuration == null) 23 | return; 24 | 25 | services.RegisterSingleton(configuration); 26 | services.RegisterSingleton(s => new Mapper(s.GetService())); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/KickStart/Services/IServiceRegistrationBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// An to build service registrations 5 | /// 6 | public interface IServiceRegistrationBuilder 7 | { 8 | /// 9 | /// Filters the types based on a . 10 | /// 11 | /// A function to test each element for a condition. 12 | /// An to build service registrations 13 | /// If the argument is null. 14 | IServiceRegistrationBuilder Types(Action predicate); 15 | 16 | /// 17 | /// Configure how the types should be registered as. 18 | /// 19 | /// A function to configure how types should be registered. 20 | /// An to build service registrations 21 | /// If the argument is null. 22 | IServiceRegistrationBuilder As(Action mapper); 23 | } -------------------------------------------------------------------------------- /src/KickStart.Autofac/AutofacOptions.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Builder; 3 | 4 | namespace KickStart.Autofac; 5 | 6 | /// 7 | /// 8 | /// 9 | public class AutofacOptions 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public AutofacOptions() 15 | { 16 | BuildOptions = ContainerBuildOptions.None; 17 | } 18 | 19 | /// 20 | /// Gets or sets the build options. 21 | /// 22 | /// 23 | /// The build options. 24 | /// 25 | public ContainerBuildOptions BuildOptions { get; set; } 26 | 27 | /// 28 | /// Gets or sets the initialize builder . 29 | /// 30 | /// 31 | /// The initialize builder . 32 | /// 33 | public Action Initializer { get; set; } 34 | 35 | /// 36 | /// Gets or sets the initialize container . 37 | /// 38 | /// 39 | /// The initialize container . 40 | /// 41 | public Action Accessor { get; set; } 42 | } -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Documentation 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - develop 8 | tags: 9 | - "v*" 10 | paths: 11 | - "docs/**" 12 | - "mkdocs.yml" 13 | 14 | permissions: 15 | contents: write 16 | 17 | jobs: 18 | build: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@v6 23 | 24 | - name: Setup Python 25 | uses: actions/setup-python@v6 26 | with: 27 | python-version: 3.x 28 | 29 | - name: Install mkdocs 30 | run: pip install mkdocs-material 31 | 32 | - name: Build Documentation 33 | run: mkdocs build 34 | 35 | - name: Upload Documentation 36 | if: success() 37 | uses: actions/upload-pages-artifact@v4 38 | with: 39 | name: github-pages 40 | path: "site/" 41 | 42 | pages: 43 | runs-on: ubuntu-latest 44 | needs: build 45 | if: success() 46 | 47 | permissions: 48 | pages: write 49 | id-token: write 50 | 51 | steps: 52 | - name: Deploy Documentation 53 | id: deployment 54 | uses: actions/deploy-pages@v4 55 | 56 | environment: 57 | name: github-pages 58 | url: ${{ steps.deployment.outputs.page_url }} 59 | -------------------------------------------------------------------------------- /src/KickStart.MongoDB/MongoStarter.cs: -------------------------------------------------------------------------------- 1 | using MongoDB.Bson.Serialization; 2 | 3 | namespace KickStart.MongoDB; 4 | 5 | /// 6 | /// A KickStart extension to initialize MongoDB. 7 | /// 8 | public class MongoStarter : IKickStarter 9 | { 10 | private readonly MongoOptions _options; 11 | 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// The options to use. 16 | public MongoStarter(MongoOptions options) 17 | { 18 | _options = options; 19 | } 20 | 21 | /// 22 | /// Runs the application KickStart extension with specified . 23 | /// 24 | /// The KickStart containing assemblies to scan. 25 | public void Run(Context context) 26 | { 27 | var classMaps = context.GetInstancesAssignableFrom(); 28 | 29 | foreach (var classMap in classMaps) 30 | { 31 | if (BsonClassMap.IsClassMapRegistered(classMap.ClassType)) 32 | continue; 33 | 34 | context.WriteLog("Register MongoDB ClassMap: {0}", classMap); 35 | 36 | BsonClassMap.RegisterClassMap(classMap); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /docs/di/simpleInjector.md: -------------------------------------------------------------------------------- 1 | # SimpleInjector 2 | 3 | The SimpleInjector extension allows registration of types to be resolved by running all instances of `ISimpleInjectorRegistration`. 4 | 5 | Basic usage 6 | 7 | ```csharp 8 | Kick.Start(config => config 9 | .IncludeAssemblyFor() // where to look 10 | .UseSimpleInjector () // initialize SimpleInjector 11 | ); 12 | ``` 13 | 14 | Using SimpleInjector with ASP.NET WebAPI 15 | 16 | ```csharp 17 | Kick.Start(c => c 18 | .LogTo(_logger.Debug) 19 | .IncludeAssemblyFor() 20 | .Data("hostProcess", "web") 21 | .UseSimpleInjector(s => s 22 | .Verify(VerificationOption.VerifyOnly) 23 | .Initialize(container => 24 | { 25 | container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle(); 26 | container.RegisterWebApiControllers(httpConfiguration); // register all controllers 27 | }) 28 | .Container(container => 29 | { 30 | httpConfiguration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); // set asp.net resolver 31 | }) 32 | ) 33 | .UseStartupTask() 34 | ); 35 | ``` 36 | 37 | To install SimpleInjector extension, run the following command in the Package Manager Console 38 | 39 | PM> Install-Package KickStart.SimpleInjector -------------------------------------------------------------------------------- /src/KickStart.Log4Net/Log4NetExtensions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | namespace KickStart; 3 | 4 | /// 5 | /// KickStart Extension for log4net. 6 | /// 7 | public static class Log4NetExtensions 8 | { 9 | private static readonly log4net.ILog _logger = log4net.LogManager.GetLogger("KickStart"); 10 | 11 | /// 12 | /// Use log4net as a logging target. 13 | /// 14 | /// The configuration builder. 15 | /// 16 | public static IConfigurationBuilder UseLog4Net(this IConfigurationBuilder configurationBuilder) 17 | { 18 | return UseLog4Net(configurationBuilder, null); 19 | } 20 | 21 | /// 22 | /// Use log4net as a logging target. 23 | /// 24 | /// The configuration builder. 25 | /// The configure action for log4net. 26 | /// 27 | public static IConfigurationBuilder UseLog4Net(this IConfigurationBuilder configurationBuilder, Action configure) 28 | { 29 | 30 | configure?.Invoke(); 31 | 32 | // register log writer 33 | configurationBuilder.LogTo(_logger.Debug); 34 | 35 | return configurationBuilder; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/KickStart.Ninject/NinjectBuilder.cs: -------------------------------------------------------------------------------- 1 | using Ninject; 2 | 3 | namespace KickStart.Ninject; 4 | 5 | /// 6 | /// Ninject configuration builder 7 | /// 8 | /// 9 | public class NinjectBuilder : INinjectBuilder 10 | { 11 | private readonly NinjectOptions _options; 12 | 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The options. 17 | public NinjectBuilder(NinjectOptions options) 18 | { 19 | _options = options; 20 | } 21 | 22 | /// 23 | /// Set the specified Ninject settings. 24 | /// 25 | /// The Ninjectsettings. 26 | /// 27 | public INinjectBuilder Settings(INinjectSettings settings) 28 | { 29 | _options.Settings = settings; 30 | return this; 31 | } 32 | 33 | /// 34 | /// Set the specified initializer. 35 | /// 36 | /// The initializer. 37 | /// 38 | public INinjectBuilder Kernal(Action initializer) 39 | { 40 | _options.InitializeKernel = initializer; 41 | return this; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /docs/di/registration.md: -------------------------------------------------------------------------------- 1 | # Generic Service Registration 2 | 3 | KickStart has a generic service registration abstraction. This allows for the creation of a generic class module that registers services for dependency injection that is container agnostic. 4 | 5 | Example module to register services 6 | 7 | ```csharp 8 | public class UserServiceModule : IServiceModule 9 | { 10 | public void Register(IServiceRegistration services, IDictionary data) 11 | { 12 | services.RegisterSingleton(); 13 | services.RegisterTransient(c => new UserService(c.GetService())); 14 | 15 | // register generic 16 | services.RegisterSingleton(r => r 17 | .Types(t => t.AssignableTo(typeof(IRepository<>))) 18 | .As(s => s.Self().ImplementedInterfaces()) 19 | ); 20 | 21 | // register all types that are assignable to IService 22 | services.RegisterSingleton(r => r 23 | .Types(t => t.AssignableTo()) 24 | .As(s => s.Self().ImplementedInterfaces()) 25 | ); 26 | 27 | // register all types that are assignable to IVehicle 28 | services.RegisterSingleton(r => r 29 | .Types(t => t.AssignableTo()) 30 | .As(s => s.Self().ImplementedInterfaces()) 31 | ); 32 | } 33 | } 34 | ``` -------------------------------------------------------------------------------- /src/KickStart.Autofac/AutofacServiceProvider.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | 3 | namespace KickStart.Autofac; 4 | 5 | /// 6 | /// Autofac implementation of . 7 | /// 8 | /// 9 | public class AutofacServiceProvider : IServiceProvider 10 | { 11 | private readonly IComponentContext _componentContext; 12 | 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// 17 | /// The component context from which services should be resolved. 18 | /// 19 | public AutofacServiceProvider(IComponentContext componentContext) 20 | { 21 | _componentContext = componentContext; 22 | } 23 | 24 | /// 25 | /// Gets the service object of the specified type. 26 | /// 27 | /// 28 | /// An object that specifies the type of service object to get. 29 | /// 30 | /// 31 | /// A service object of type ; or 32 | /// if there is no service object of type . 33 | /// 34 | public object GetService(Type serviceType) 35 | { 36 | return _componentContext.ResolveOptional(serviceType); 37 | } 38 | } -------------------------------------------------------------------------------- /src/KickStart.Serilog/SerilogStarter.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | 3 | namespace KickStart; 4 | 5 | /// 6 | /// A KickStart extension to initialize Serilog. 7 | /// 8 | public class SerilogStarter : IKickStarter 9 | { 10 | private readonly SerilogOptions _options; 11 | 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// The options to use. 16 | public SerilogStarter(SerilogOptions options) 17 | { 18 | _options = options; 19 | } 20 | 21 | /// 22 | /// Runs the application KickStart extension with specified . 23 | /// 24 | /// The KickStart containing assemblies to scan. 25 | public void Run(Context context) 26 | { 27 | var configuration = new LoggerConfiguration(); 28 | 29 | var configurations = context.GetInstancesAssignableFrom(); 30 | 31 | foreach (var c in configurations) 32 | { 33 | context.WriteLog("Serilog Configuration: {0}", configuration); 34 | c.Configure(configuration); 35 | } 36 | 37 | _options.Configure?.Invoke(configuration); 38 | 39 | // Activate the configuration 40 | Serilog.Log.Logger = configuration.CreateLogger(); 41 | } 42 | } -------------------------------------------------------------------------------- /src/KickStart.DependencyInjection/IDependencyInjectionBuilder.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | 4 | namespace KickStart.DependencyInjection; 5 | 6 | /// 7 | /// Microsoft.Extensions.DependencyInjection configuration builder 8 | /// 9 | public interface IDependencyInjectionBuilder 10 | { 11 | /// 12 | /// Sets the creator . 13 | /// 14 | /// The creator. 15 | /// 16 | IDependencyInjectionBuilder Creator(Func creator); 17 | 18 | 19 | /// 20 | /// Sets the service provider accessor . Resolve services under this . 21 | /// 22 | /// The service provider accessor . 23 | /// 24 | IDependencyInjectionBuilder Container(Action accessor); 25 | 26 | /// 27 | /// Sets the initialize services . Register services under this . 28 | /// 29 | /// The initialize services . 30 | /// 31 | IDependencyInjectionBuilder Initialize(Action initializer); 32 | } 33 | -------------------------------------------------------------------------------- /src/KickStart.DependencyInjection/DependencyInjectionOptions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | 4 | namespace KickStart.DependencyInjection; 5 | 6 | /// 7 | /// Microsoft.Extensions.DependencyInjection options class 8 | /// 9 | public class DependencyInjectionOptions 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | public DependencyInjectionOptions() 15 | { 16 | Creator = () => new ServiceCollection(); 17 | } 18 | 19 | /// 20 | /// Gets or sets the service provider accessor . 21 | /// 22 | /// 23 | /// The accessor. 24 | /// 25 | public Action Accessor { get; set; } 26 | 27 | /// 28 | /// Gets or sets the creator . 29 | /// 30 | /// 31 | /// The creator . 32 | /// 33 | public Func Creator { get; set; } 34 | 35 | /// 36 | /// Gets or sets the initialize services . 37 | /// 38 | /// 39 | /// The initialize services . 40 | /// 41 | public Action Initializer { get; set; } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/KickStart.EntityChange/EntityChangeStarter.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.EntityChange; 2 | 3 | /// 4 | /// A KickStart extension to initialize EntityChange. 5 | /// 6 | public class EntityChangeStarter : IKickStarter 7 | { 8 | private readonly EntityChangeOptions _options; 9 | 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The options to use. 14 | public EntityChangeStarter(EntityChangeOptions options) 15 | { 16 | _options = options; 17 | } 18 | 19 | /// 20 | /// Runs the application KickStart extension with specified . 21 | /// 22 | /// The KickStart containing assemblies to scan. 23 | public void Run(Context context) 24 | { 25 | var profiles = context.GetInstancesAssignableFrom(); 26 | 27 | var configuration = global::EntityChange.EntityConfiguration.Default; 28 | configuration.Configure(c => 29 | { 30 | foreach (var profile in profiles) 31 | { 32 | context.WriteLog("EntityChange Profile: {0}", profile); 33 | c.Profile(profile); 34 | } 35 | }); 36 | 37 | if (_options.Configure != null) 38 | configuration.Configure(_options.Configure); 39 | 40 | } 41 | } -------------------------------------------------------------------------------- /docs/di/dependencyInjection.md: -------------------------------------------------------------------------------- 1 | # DependencyInjection 2 | 3 | The DependencyInjection extension allows using Microsoft.Extensions.DependencyInjection for dependency injection. 4 | 5 | Basic Usage 6 | 7 | ```csharp 8 | Kick.Start(config => config 9 | .LogTo(_output.WriteLine) 10 | .IncludeAssemblyFor() // where to look 11 | .UseDependencyInjection() // initialize DependencyInjection 12 | ); 13 | ``` 14 | 15 | Integrate with asp.net core 2.0 16 | 17 | ```csharp 18 | public class Startup 19 | { 20 | public Startup(IConfiguration configuration) 21 | { 22 | Configuration = configuration; 23 | } 24 | 25 | public IConfiguration Configuration { get; } 26 | 27 | // This method gets called by the runtime. Use this method to add services to the container. 28 | public void ConfigureServices(IServiceCollection services) 29 | { 30 | // this will auto register logging and run the DependencyInjection startup 31 | services.KickStart(c => c 32 | .IncludeAssemblyFor() // where to look 33 | .Data("configuration", Configuration) // pass configuration to all startup modules 34 | .Data("hostProcess", "web") // used for conditional registration 35 | .UseStartupTask() // run startup task 36 | ); 37 | } 38 | } 39 | ``` 40 | 41 | To install DependencyInjection extension, run the following command in the Package Manager Console 42 | 43 | PM> Install-Package KickStart.DependencyInjection 44 | -------------------------------------------------------------------------------- /src/KickStart.Ninject/NinjectStarter.cs: -------------------------------------------------------------------------------- 1 | using Ninject; 2 | using Ninject.Modules; 3 | 4 | namespace KickStart.Ninject; 5 | 6 | /// 7 | /// Ninject KickStart extention 8 | /// 9 | /// 10 | public class NinjectStarter : IKickStarter 11 | { 12 | private readonly NinjectOptions _options; 13 | 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | /// The options. 18 | public NinjectStarter(NinjectOptions options) 19 | { 20 | _options = options; 21 | } 22 | 23 | /// 24 | /// Runs the application KickStart extension with specified . 25 | /// 26 | /// The KickStart containing assemblies to scan. 27 | public void Run(Context context) 28 | { 29 | var modules = context.GetInstancesAssignableFrom().ToArray(); 30 | 31 | foreach (var module in modules) 32 | { 33 | context.WriteLog("Register Ninject Module: {0}", module); 34 | } 35 | 36 | context.WriteLog("Create Ninject Kernel..."); 37 | 38 | var settings = _options.Settings ?? new NinjectSettings(); 39 | var kernel = new StandardKernel(settings, modules); 40 | 41 | _options.InitializeKernel?.Invoke(kernel); 42 | 43 | context.SetServiceProvider(kernel); 44 | } 45 | } -------------------------------------------------------------------------------- /src/KickStart/StartupTask/StartupTaskBase.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.StartupTask; 2 | 3 | /// 4 | /// Base class for start tasks, must override or 5 | /// 6 | public abstract class StartupTaskBase : IStartupTask 7 | { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | protected StartupTaskBase() 12 | { 13 | Priority = int.MaxValue; 14 | } 15 | 16 | /// 17 | /// Gets the priority of this task. Lower numbers run first. 18 | /// 19 | /// 20 | /// The priority of this task. 21 | /// 22 | public int Priority { get; set; } 23 | 24 | /// 25 | /// Runs the startup task with the specified context . 26 | /// 27 | /// The data dictionary shared with all starter modules. 28 | public virtual void Run(IDictionary data) 29 | { 30 | throw new NotImplementedException(); 31 | } 32 | 33 | /// 34 | /// Runs the startup task with the specified context asynchronously. 35 | /// 36 | /// The data dictionary shared with all starter modules. 37 | public virtual Task RunAsync(IDictionary data) 38 | { 39 | return Task.Factory.StartNew(() => Run(data)); 40 | } 41 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "01:00" 8 | timezone: "America/Chicago" 9 | open-pull-requests-limit: 10 10 | 11 | - package-ecosystem: nuget 12 | directory: "/" 13 | schedule: 14 | interval: daily 15 | time: "02:00" 16 | timezone: "America/Chicago" 17 | open-pull-requests-limit: 10 18 | groups: 19 | Azure: 20 | patterns: 21 | - "Azure.*" 22 | - "Microsoft.Azure.*" 23 | - "Microsoft.Extensions.Azure" 24 | AspNetCoreHealthChecks: 25 | patterns: 26 | - "AspNetCore.HealthChecks.*" 27 | AspNetCore: 28 | patterns: 29 | - "Microsoft.AspNetCore.*" 30 | - "Microsoft.Extensions.Features" 31 | MicrosoftExtensions: 32 | patterns: 33 | - "Microsoft.Extensions.*" 34 | EntityFrameworkCore: 35 | patterns: 36 | - "Microsoft.EntityFrameworkCore.*" 37 | OpenTelemetry: 38 | patterns: 39 | - "OpenTelemetry.*" 40 | Serilog: 41 | patterns: 42 | - "Serilog" 43 | - "Serilog.*" 44 | Hangfire: 45 | patterns: 46 | - "Hangfire" 47 | - "Hangfire.*" 48 | Testcontainers: 49 | patterns: 50 | - "Testcontainers.*" 51 | xUnit: 52 | patterns: 53 | - "xunit" 54 | - "xunit.assert" 55 | - "xunit.core" 56 | - "xunit.extensibility.*" 57 | - "xunit.runner.*" 58 | -------------------------------------------------------------------------------- /src/KickStart.Serilog/SerilogExtensions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | namespace KickStart; 3 | 4 | /// 5 | /// KickStart Extension for Serilog. 6 | /// 7 | public static class SerilogExtensions 8 | { 9 | /// 10 | /// Use Serilog as a logging target. 11 | /// 12 | /// The configuration builder. 13 | /// 14 | public static IConfigurationBuilder UseSerilog(this IConfigurationBuilder configurationBuilder) 15 | { 16 | return UseSerilog(configurationBuilder, null); 17 | } 18 | 19 | 20 | /// 21 | /// Use Serilog as a logging target. 22 | /// 23 | /// The configuration builder. 24 | /// The configure action for Serilog. 25 | /// 26 | public static IConfigurationBuilder UseSerilog(this IConfigurationBuilder configurationBuilder, Action configure) 27 | { 28 | var options = new SerilogOptions { Configure = configure }; 29 | var starter = new SerilogStarter(options); 30 | 31 | configurationBuilder.ExcludeAssemblyFor(); 32 | configurationBuilder.ExcludeAssemblyFor(); 33 | configurationBuilder.ExcludeName("Serilog"); 34 | 35 | configurationBuilder.Use(starter); 36 | 37 | // register log writer 38 | configurationBuilder.LogTo(Serilog.Log.Debug); 39 | 40 | return configurationBuilder; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/KickStart.NLog/NLogExtensions.cs: -------------------------------------------------------------------------------- 1 | // ReSharper disable once CheckNamespace 2 | namespace KickStart; 3 | 4 | /// 5 | /// KickStart Extension for NLog. 6 | /// 7 | public static class NLogExtensions 8 | { 9 | private static NLog.Logger _logger = NLog.LogManager.GetLogger("KickStart"); 10 | 11 | /// 12 | /// Use NLog as a logging target. 13 | /// 14 | /// The configuration builder. 15 | /// 16 | public static IConfigurationBuilder UseNLog(this IConfigurationBuilder configurationBuilder) 17 | { 18 | return UseNLog(configurationBuilder, null); 19 | } 20 | 21 | 22 | /// 23 | /// Use NLog as a logging target. 24 | /// 25 | /// The configuration builder. 26 | /// The configure action for NLog. 27 | /// 28 | public static IConfigurationBuilder UseNLog(this IConfigurationBuilder configurationBuilder, Action configure) 29 | { 30 | if (configure != null) 31 | { 32 | var configuration = global::NLog.LogManager.Configuration ?? new NLog.Config.LoggingConfiguration(); 33 | configure(configuration); 34 | 35 | // Activate the configuration 36 | NLog.LogManager.Configuration = configuration; 37 | } 38 | 39 | // register log writer 40 | configurationBuilder.LogTo(_logger.Debug); 41 | 42 | return configurationBuilder; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Directory.Packages.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | false 5 | $(NoWarn);NU1507 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/KickStart.SimpleInjector/ISimpleInjectorBuilder.cs: -------------------------------------------------------------------------------- 1 | using SimpleInjector; 2 | 3 | namespace KickStart.SimpleInjector; 4 | 5 | /// 6 | /// SimpleInjector configuration builder 7 | /// 8 | public interface ISimpleInjectorBuilder 9 | { 10 | /// 11 | /// Sets the creator . 12 | /// 13 | /// The creator. 14 | /// 15 | ISimpleInjectorBuilder Creator(Func creator); 16 | 17 | /// 18 | /// Sets the initialize container . Register services under this . 19 | /// 20 | /// The initialize container . 21 | /// 22 | ISimpleInjectorBuilder Initialize(Action initializer); 23 | 24 | /// 25 | /// Sets the container accessor . Resolve services under this . 26 | /// 27 | /// The container accessor . 28 | /// 29 | ISimpleInjectorBuilder Container(Action accessor); 30 | 31 | 32 | /// 33 | /// Verifies the Container with the specified . 34 | /// 35 | /// Specifies how the container should verify its configuration. 36 | /// 37 | ISimpleInjectorBuilder Verify(VerificationOption? options); 38 | } -------------------------------------------------------------------------------- /src/KickStart.SimpleInjector/SimpleInjectorOptions.cs: -------------------------------------------------------------------------------- 1 | using SimpleInjector; 2 | 3 | namespace KickStart.SimpleInjector; 4 | 5 | /// 6 | /// SimpleInjector options class 7 | /// 8 | public class SimpleInjectorOptions 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | public SimpleInjectorOptions() 14 | { 15 | Creator = () => new Container(); 16 | } 17 | 18 | /// 19 | /// Gets or sets the container accessor . 20 | /// 21 | /// 22 | /// The container accessor . 23 | /// 24 | public Action Accessor { get; set; } 25 | 26 | /// 27 | /// Gets or sets the creator . 28 | /// 29 | /// 30 | /// The creator . 31 | /// 32 | public Func Creator { get; set; } 33 | 34 | /// 35 | /// Gets or sets the initialize container . 36 | /// 37 | /// 38 | /// The initialize container . 39 | /// 40 | public Action Initializer { get; set; } 41 | 42 | /// 43 | /// Gets or sets how the container should verify its configuration. 44 | /// 45 | /// 46 | /// How the container should verify its configuration. 47 | /// 48 | public VerificationOption? VerificationOption { get; set; } 49 | } 50 | -------------------------------------------------------------------------------- /test/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | Copyright © $([System.DateTime]::Now.ToString(yyyy)) LoreSoft 4 | LoreSoft 5 | en-US 6 | false 7 | 8 | 9 | 10 | embedded 11 | true 12 | false 13 | 14 | 15 | 16 | latest 17 | enable 18 | 1591 19 | 20 | 21 | 22 | v 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/KickStart.AutoMapper/AutoMapperStarter.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | 3 | namespace KickStart.AutoMapper; 4 | 5 | /// 6 | /// A KickStart extension to initialize AutoMapper. 7 | /// 8 | public class AutoMapperStarter : IKickStarter 9 | { 10 | /// The AutoMapper configuration data key name 11 | public const string AutoMapperConfiguration = "AutoMapper:Configuration"; 12 | 13 | private readonly AutoMapperOptions _options; 14 | 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | /// The options to use. 19 | public AutoMapperStarter(AutoMapperOptions options) 20 | { 21 | _options = options; 22 | } 23 | 24 | /// 25 | /// Runs the application KickStart extension with specified . 26 | /// 27 | /// The KickStart containing assemblies to scan. 28 | public void Run(Context context) 29 | { 30 | var profiles = context.GetInstancesAssignableFrom(); 31 | 32 | var configuration = new MapperConfiguration(config => 33 | { 34 | foreach (var profile in profiles) 35 | { 36 | context.WriteLog("AutoMapper Profile: {0}", profile); 37 | 38 | config.AddProfile(profile); 39 | } 40 | 41 | _options.Initialize?.Invoke(config); 42 | }); 43 | 44 | 45 | if (_options.Validate) 46 | configuration.AssertConfigurationIsValid(); 47 | 48 | context.Data[AutoMapperConfiguration] = configuration; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/KickStart.AutoMapper/AutoMapperBuilder.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | 3 | namespace KickStart.AutoMapper; 4 | 5 | /// 6 | /// Fluent builder. 7 | /// 8 | public class AutoMapperBuilder : IAutoMapperBuilder 9 | { 10 | private readonly AutoMapperOptions _options; 11 | 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// The AutoMapperOptions to configure. 16 | public AutoMapperBuilder(AutoMapperOptions options) 17 | { 18 | _options = options; 19 | } 20 | 21 | /// 22 | /// Call after configuration to validate the state of the mapping. 23 | /// 24 | /// if set to true to call to validate. 25 | /// 26 | /// Fluent builder. 27 | /// 28 | public IAutoMapperBuilder Validate(bool value = true) 29 | { 30 | _options.Validate = value; 31 | return this; 32 | } 33 | 34 | /// 35 | /// Passes the current to add additional configuration options. 36 | /// 37 | /// The delegate to call for additional configuration. 38 | /// 39 | /// Fluent builder. 40 | /// 41 | public IAutoMapperBuilder Initialize(Action configuration) 42 | { 43 | _options.Initialize = configuration; 44 | return this; 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /src/KickStart.Unity/UnityExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Unity; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace KickStart; 5 | 6 | /// 7 | /// KickStart Unity extension methods 8 | /// 9 | public static class UnityExtensions 10 | { 11 | /// 12 | /// Use the KickStart extension to configure Unity. 13 | /// 14 | /// The configuration builder. 15 | /// 16 | /// A fluent to configure KickStart. 17 | /// 18 | public static IConfigurationBuilder UseUnity(this IConfigurationBuilder configurationBuilder) 19 | { 20 | return UseUnity(configurationBuilder, null); 21 | } 22 | 23 | /// 24 | /// Use the KickStart extension to configure Unity. 25 | /// 26 | /// The configuration builder. 27 | /// The to configure Unity options. 28 | /// 29 | /// A fluent to configure KickStart. 30 | /// 31 | public static IConfigurationBuilder UseUnity(this IConfigurationBuilder configurationBuilder, Action configure) 32 | { 33 | var options = new UnityOptions(); 34 | var starter = new UnityStarter(options); 35 | 36 | if (configure != null) 37 | { 38 | var builder = new UnityBuilder(options); 39 | configure(builder); 40 | } 41 | 42 | configurationBuilder.ExcludeAssemblyFor(); 43 | configurationBuilder.ExcludeAssemblyFor(); 44 | configurationBuilder.Use(starter); 45 | 46 | return configurationBuilder; 47 | } 48 | } -------------------------------------------------------------------------------- /src/KickStart.Ninject/NinjectExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Ninject; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace KickStart; 5 | 6 | /// 7 | /// KickStart Extension for Ninject. 8 | /// 9 | public static class NinjectExtensions 10 | { 11 | /// 12 | /// Use the KickStart extension to configure Ninject. 13 | /// 14 | /// The configuration builder. 15 | /// 16 | /// A fluent to configure KickStart. 17 | /// 18 | public static IConfigurationBuilder UseNinject(this IConfigurationBuilder configurationBuilder) 19 | { 20 | return UseNinject(configurationBuilder, null); 21 | } 22 | 23 | /// 24 | /// Use the KickStart extension to configure Ninject. 25 | /// 26 | /// The configuration builder. 27 | /// The to configure Ninject options. 28 | /// 29 | /// A fluent to configure KickStart. 30 | /// 31 | public static IConfigurationBuilder UseNinject(this IConfigurationBuilder configurationBuilder, Action configure) 32 | { 33 | var options = new NinjectOptions(); 34 | var service = new NinjectStarter(options); 35 | 36 | if (configure != null) 37 | { 38 | var builder = new NinjectBuilder(options); 39 | configure(builder); 40 | } 41 | 42 | configurationBuilder.ExcludeAssemblyFor(); 43 | configurationBuilder.ExcludeAssemblyFor(); 44 | configurationBuilder.Use(service); 45 | 46 | return configurationBuilder; 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /src/KickStart.Autofac/AutofacExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Autofac; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace KickStart; 5 | 6 | /// 7 | /// KickStart Extension for Autofac. 8 | /// 9 | public static class AutofacExtensions 10 | { 11 | /// 12 | /// Use the KickStart extension to configure Autofac. 13 | /// 14 | /// The configuration builder. 15 | /// 16 | /// A fluent to configure KickStart. 17 | /// 18 | public static IConfigurationBuilder UseAutofac(this IConfigurationBuilder configurationBuilder) 19 | { 20 | return UseAutofac(configurationBuilder, null); 21 | } 22 | 23 | /// 24 | /// Use the KickStart extension to configure Autofac. 25 | /// 26 | /// The configuration builder. 27 | /// The to configure Autofac options. 28 | /// 29 | /// A fluent to configure KickStart. 30 | /// 31 | public static IConfigurationBuilder UseAutofac(this IConfigurationBuilder configurationBuilder, Action configure) 32 | { 33 | var options = new AutofacOptions(); 34 | var service = new AutofacStarter(options); 35 | 36 | if (configure != null) 37 | { 38 | var builder = new AutofacBuilder(options); 39 | configure(builder); 40 | } 41 | 42 | configurationBuilder.ExcludeAssemblyFor(); 43 | configurationBuilder.ExcludeAssemblyFor(); 44 | configurationBuilder.Use(service); 45 | 46 | return configurationBuilder; 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Stale Items 2 | on: 3 | schedule: 4 | - cron: "0 6 * * 0" 5 | 6 | workflow_dispatch: 7 | 8 | jobs: 9 | stale: 10 | name: Mark and Close Stale Items 11 | runs-on: ubuntu-latest 12 | permissions: 13 | issues: write 14 | pull-requests: write 15 | steps: 16 | - uses: actions/stale@v10 17 | with: 18 | repo-token: ${{ secrets.GITHUB_TOKEN }} 19 | 20 | days-before-stale: 365 21 | days-before-close: 45 22 | 23 | # Issue configuration 24 | stale-issue-label: "stale" 25 | close-issue-label: "closed:stale" 26 | exempt-issue-labels: "pinned,security,enhancement,bug,backlog,epic" 27 | 28 | stale-issue-message: | 29 | ## ⏰ Stale Issue 30 | 31 | This issue has had no activity for 1 year. 32 | It will be closed in 45 days unless there is new activity. 33 | To keep it open, comment or remove the `stale` label. 34 | 35 | close-issue-message: | 36 | ## 🔒 Closed: Inactive Issue 37 | 38 | Closed after 45 days of inactivity. 39 | To reopen, comment with a reason and a maintainer will review. 40 | 41 | # PR configuration 42 | stale-pr-label: "stale" 43 | close-pr-label: "closed:stale" 44 | exempt-pr-labels: "pinned,work-in-progress,ready-for-review" 45 | 46 | stale-pr-message: | 47 | ## ⏰ Stale Pull Request 48 | 49 | No activity for 1 year. Will close in 45 days unless updated. 50 | To keep open, push commits, comment, or remove the `stale` label. 51 | 52 | close-pr-message: | 53 | ## 🔒 Closed: Inactive PR 54 | 55 | Closed after 45 days of inactivity. 56 | To continue, reopen or submit a new PR and reference this one. 57 | -------------------------------------------------------------------------------- /src/KickStart.Autofac/AutofacBuilder.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | using Autofac.Builder; 3 | 4 | namespace KickStart.Autofac; 5 | 6 | /// 7 | /// Autofac fluent builder 8 | /// 9 | /// 10 | public class AutofacBuilder : IAutofacBuilder 11 | { 12 | private readonly AutofacOptions _options; 13 | 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | /// The options. 18 | public AutofacBuilder(AutofacOptions options) 19 | { 20 | _options = options; 21 | } 22 | 23 | /// 24 | /// Sets Autofac build options. 25 | /// 26 | /// The build options. 27 | /// 28 | public IAutofacBuilder Options(ContainerBuildOptions buildOptions) 29 | { 30 | _options.BuildOptions = buildOptions; 31 | return this; 32 | } 33 | 34 | /// 35 | /// Sets the initialize builder . Register services under this . 36 | /// 37 | /// The initialize builder . 38 | /// 39 | public IAutofacBuilder Initialize(Action initializer) 40 | { 41 | _options.Initializer = initializer; 42 | return this; 43 | } 44 | 45 | /// 46 | /// Sets the container accessor . Resolve services under this . 47 | /// 48 | /// The container accessor . 49 | /// 50 | public IAutofacBuilder Container(Action accessor) 51 | { 52 | _options.Accessor = accessor; 53 | return this; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/KickStart.SimpleInjector/SimpleInjectorExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart.SimpleInjector; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace KickStart; 5 | 6 | /// 7 | /// KickStart Extension for SimpleInjector. 8 | /// 9 | public static class SimpleInjectorExtensions 10 | { 11 | /// 12 | /// Use the KickStart extension to configure SimpleInjector. 13 | /// 14 | /// The configuration builder. 15 | /// 16 | /// A fluent to configure KickStart. 17 | /// 18 | public static IConfigurationBuilder UseSimpleInjector(this IConfigurationBuilder configurationBuilder) 19 | { 20 | return UseSimpleInjector(configurationBuilder, null); 21 | } 22 | 23 | /// 24 | /// Use the KickStart extension to configure SimpleInjector. 25 | /// 26 | /// The configuration builder. 27 | /// The to configure SimpleInjector options. 28 | /// 29 | /// A fluent to configure KickStart. 30 | /// 31 | public static IConfigurationBuilder UseSimpleInjector(this IConfigurationBuilder configurationBuilder, Action configure) 32 | { 33 | var options = new SimpleInjectorOptions(); 34 | var starter = new SimpleInjectorStarter(options); 35 | 36 | if (configure != null) 37 | { 38 | var builder = new SimpleInjectorBuilder(options); 39 | configure(builder); 40 | } 41 | 42 | configurationBuilder.ExcludeAssemblyFor(); 43 | configurationBuilder.ExcludeAssemblyFor(); 44 | configurationBuilder.Use(starter); 45 | 46 | return configurationBuilder; 47 | } 48 | } -------------------------------------------------------------------------------- /src/KickStart/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | 3 | namespace KickStart; 4 | 5 | /// 6 | /// A class defining the KickStart configuration. 7 | /// 8 | public class Configuration 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | public Configuration() 14 | { 15 | Assemblies = new AssemblyResolver(m => LogWriter?.Invoke(m)); 16 | 17 | // exclude system assemblies 18 | Assemblies.ExcludeName("mscorlib"); 19 | Assemblies.ExcludeName("Microsoft"); 20 | Assemblies.ExcludeName("System"); 21 | 22 | // exclude self 23 | Assemblies.ExcludeAssemblyFor(); 24 | 25 | Starters = new List(); 26 | Data = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); 27 | } 28 | 29 | /// 30 | /// Gets the assemblies used by KickStart. 31 | /// 32 | /// 33 | /// The assemblies use by KickStart. 34 | /// 35 | public AssemblyResolver Assemblies { get; } 36 | 37 | /// 38 | /// Gets the extensions to use. 39 | /// 40 | /// 41 | /// The IKickStarter extensions to use. 42 | /// 43 | public IList Starters { get; } 44 | 45 | /// 46 | /// Gets the data dictionary shared with all starter modules. 47 | /// 48 | /// 49 | /// The data dictionary shared with all starter modules. 50 | /// 51 | public IDictionary Data { get; } 52 | 53 | /// 54 | /// Gets or set the where log messages will be written. 55 | /// 56 | /// 57 | /// The where log messages will be written. 58 | /// 59 | public Action LogWriter { get; set; } 60 | } -------------------------------------------------------------------------------- /src/KickStart/Services/IServiceRegistration.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// An for service registration 5 | /// 6 | public interface IServiceRegistration 7 | { 8 | /// 9 | /// Gets the current service . 10 | /// 11 | /// The current service 12 | Context ServiceContext { get; } 13 | 14 | /// 15 | /// Registers a service of the type specified in with an 16 | /// implementation of the type specified in using 17 | /// the specified . 18 | /// 19 | /// The type of the service to register. 20 | /// The implementation type of the service. 21 | /// The service lifetime. 22 | /// 23 | /// A reference to this instance after the operation has completed. 24 | /// 25 | IServiceRegistration Register(Type serviceType, Type implementationType, ServiceLifetime lifetime); 26 | 27 | /// 28 | /// Registers a service of the type specified in with a 29 | /// factory specified in using 30 | /// the specified . 31 | /// 32 | /// The type of the service to register. 33 | /// The factory that creates the service. 34 | /// The service lifetime. 35 | /// 36 | /// A reference to this instance after the operation has completed. 37 | /// 38 | /// 39 | IServiceRegistration Register(Type serviceType, Func implementationFactory, ServiceLifetime lifetime); 40 | 41 | } -------------------------------------------------------------------------------- /src/KickStart/Services/IServiceTypeMapper.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// An to configure how service mappings are registered. 5 | /// 6 | public interface IServiceTypeMapper 7 | { 8 | /// 9 | /// Registers each concrete type as itself. 10 | /// 11 | /// An to configure how implementations are registered. 12 | IServiceTypeMapper Self(); 13 | 14 | /// 15 | /// Registers each concrete type as . 16 | /// 17 | /// The type to register as. 18 | /// An to configure how implementations are registered. 19 | IServiceTypeMapper Type(); 20 | 21 | /// 22 | /// Registers each concrete type as each of the specified . 23 | /// 24 | /// The types to register as. 25 | /// An to configure how implementations are registered. 26 | /// If the argument is null. 27 | IServiceTypeMapper Types(params Type[] types); 28 | 29 | /// 30 | /// Registers each concrete type as each of the specified . 31 | /// 32 | /// The types to register as. 33 | /// An to configure how implementations are registered. 34 | /// If the argument is null. 35 | IServiceTypeMapper Types(IEnumerable types); 36 | 37 | /// 38 | /// Registers each concrete type as all of its implemented interfaces. 39 | /// 40 | /// An to configure how implementations are registered. 41 | IServiceTypeMapper ImplementedInterfaces(); 42 | } -------------------------------------------------------------------------------- /src/KickStart.DependencyInjection/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart; 2 | 3 | using Microsoft.Extensions.Logging; 4 | 5 | // ReSharper disable once CheckNamespace 6 | namespace Microsoft.Extensions.DependencyInjection; 7 | 8 | /// 9 | /// Extension methods for 10 | /// 11 | public static class ServiceCollectionExtensions 12 | { 13 | /// 14 | /// Configure and run the KickStart extensions. 15 | /// 16 | /// 17 | /// The to configure KickStart before execution of the extensions. 18 | /// Configure KickStart to use startup tasks. 19 | /// config 21 | /// .IncludeAssemblyFor() 22 | /// .UseStartupTask() 23 | /// );]]> 24 | /// 25 | public static IServiceCollection KickStart(this IServiceCollection services, Action configurator) 26 | { 27 | var logger = CreateLogger(services); 28 | var canWrite = logger?.IsEnabled(LogLevel.Debug) ?? false; 29 | 30 | Kick.Start(builder => 31 | { 32 | builder 33 | .LogTo(m => { if (canWrite) logger?.LogDebug(m); }) 34 | .UseDependencyInjection(d => d.Creator(() => services)); 35 | 36 | configurator?.Invoke(builder); 37 | }); 38 | 39 | return services; 40 | } 41 | 42 | private static ILogger CreateLogger(IServiceCollection services) 43 | { 44 | try 45 | { 46 | var serviceProvider = services.BuildServiceProvider(); 47 | var loggerFactory = serviceProvider.GetService(); 48 | var logger = loggerFactory?.CreateLogger(typeof(Kick)); 49 | return logger; 50 | } 51 | catch (Exception) 52 | { 53 | // azure functions doesn't allow using services at startup. 54 | return null; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/KickStart.DependencyInjection/DependencyInjectionBuilder.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | 4 | namespace KickStart.DependencyInjection; 5 | 6 | /// 7 | /// Microsoft.Extensions.DependencyInjection configuration builder 8 | /// 9 | public class DependencyInjectionBuilder : IDependencyInjectionBuilder 10 | { 11 | private readonly DependencyInjectionOptions _options; 12 | 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | /// The options. 17 | public DependencyInjectionBuilder(DependencyInjectionOptions options) 18 | { 19 | _options = options; 20 | } 21 | 22 | /// 23 | /// Sets the service provider accessor . Resolve services under this . 24 | /// 25 | /// The service provider accessor . 26 | /// 27 | public IDependencyInjectionBuilder Container(Action accessor) 28 | { 29 | _options.Accessor = accessor; 30 | return this; 31 | } 32 | 33 | /// 34 | /// Sets the creator . 35 | /// 36 | /// The creator. 37 | /// 38 | public IDependencyInjectionBuilder Creator(Func creator) 39 | { 40 | _options.Creator = creator; 41 | return this; 42 | } 43 | 44 | /// 45 | /// Sets the initialize services . Register services under this . 46 | /// 47 | /// The initialize services . 48 | /// 49 | public IDependencyInjectionBuilder Initialize(Action initializer) 50 | { 51 | _options.Initializer = initializer; 52 | return this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/KickStart.Unity/UnityStarter.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | using Unity; 4 | 5 | namespace KickStart.Unity; 6 | 7 | /// 8 | /// KickStart extension for Unity 9 | /// 10 | /// 11 | public class UnityStarter : IKickStarter 12 | { 13 | private readonly UnityOptions _options; 14 | 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | /// The options. 19 | public UnityStarter(UnityOptions options) 20 | { 21 | _options = options; 22 | } 23 | 24 | /// 25 | /// Runs the application KickStart extension with specified . 26 | /// 27 | /// The KickStart containing assemblies to scan. 28 | public void Run(Context context) 29 | { 30 | 31 | var container = new UnityContainer(); 32 | 33 | RegisterUnity(context, container); 34 | RegisterServiceModule(context, container); 35 | 36 | _options.InitializeContainer?.Invoke(container); 37 | 38 | var provider = new UnityServiceProvider(container); 39 | context.SetServiceProvider(provider); 40 | } 41 | 42 | private void RegisterUnity(Context context, IUnityContainer container) 43 | { 44 | var modules = context.GetInstancesAssignableFrom(); 45 | foreach (var module in modules) 46 | { 47 | context.WriteLog("Register Unity Module: {0}", module); 48 | 49 | module.Register(container); 50 | } 51 | } 52 | 53 | 54 | private void RegisterServiceModule(Context context, IUnityContainer container) 55 | { 56 | var wrapper = new UnityServiceRegistration(context, container); 57 | var modules = context.GetInstancesAssignableFrom(); 58 | foreach (var module in modules) 59 | { 60 | context.WriteLog("Register Service Module: {0}", module); 61 | 62 | module.Register(wrapper, context.Data); 63 | } 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | Application start-up helper to initialize things like an IoC container, register mapping information or run a task. 4 | Copyright © $([System.DateTime]::Now.ToString(yyyy)) LoreSoft 5 | LoreSoft 6 | en-US 7 | true 8 | startup;bootstrap;bootstraper;ioc;container;initialization 9 | https://github.com/loresoft/KickStart 10 | MIT 11 | logo.png 12 | README.md 13 | git 14 | https://github.com/loresoft/KickStart 15 | true 16 | 17 | 18 | 19 | embedded 20 | true 21 | false 22 | 23 | 24 | 25 | true 26 | 27 | 28 | 29 | en-US 30 | latest 31 | enable 32 | 1591 33 | 34 | 35 | 36 | v 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | true 47 | \ 48 | false 49 | 50 | 51 | true 52 | \ 53 | false 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /KickStart.slnx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/KickStart.Autofac/AutofacStarter.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | 3 | using KickStart.Services; 4 | 5 | namespace KickStart.Autofac; 6 | 7 | /// 8 | /// KickStart extension for Autofac 9 | /// 10 | public class AutofacStarter : IKickStarter 11 | { 12 | private readonly AutofacOptions _options; 13 | 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | /// The options. 18 | public AutofacStarter(AutofacOptions options) 19 | { 20 | _options = options; 21 | } 22 | 23 | /// 24 | /// Runs the application KickStart extension with specified . 25 | /// 26 | /// The KickStart containing assemblies to scan. 27 | public void Run(Context context) 28 | { 29 | var builder = new ContainerBuilder(); 30 | 31 | RegisterAutofacModule(context, builder); 32 | RegisterServiceModule(context, builder); 33 | 34 | _options?.Initializer?.Invoke(builder); 35 | 36 | context.WriteLog("Create Autofac Container..."); 37 | 38 | var container = builder.Build(_options.BuildOptions); 39 | 40 | _options?.Accessor?.Invoke(container); 41 | 42 | var provider = new AutofacServiceProvider(container); 43 | context.SetServiceProvider(provider); 44 | } 45 | 46 | 47 | private void RegisterAutofacModule(Context context, ContainerBuilder builder) 48 | { 49 | var modules = context.GetInstancesAssignableFrom(); 50 | foreach (var module in modules) 51 | { 52 | context.WriteLog("Register Autofac Module: {0}", module); 53 | 54 | builder.RegisterModule(module); 55 | } 56 | } 57 | 58 | private void RegisterServiceModule(Context context, ContainerBuilder builder) 59 | { 60 | var wrapper = new AutofacServiceRegistration(context, builder); 61 | var modules = context.GetInstancesAssignableFrom(); 62 | foreach (var module in modules) 63 | { 64 | context.WriteLog("Register Service Module: {0}", module); 65 | 66 | module.Register(wrapper, context.Data); 67 | } 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /test/KickStart.EntityChange.Tests/EntityCompareTests.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | using EntityChange; 4 | 5 | using Test.Core; 6 | 7 | namespace KickStart.EntityChange.Tests; 8 | 9 | public class EntityCompareTests 10 | { 11 | private readonly ITestOutputHelper _output; 12 | 13 | public EntityCompareTests(ITestOutputHelper output) 14 | { 15 | _output = output; 16 | } 17 | 18 | [Fact] 19 | public void Configure() 20 | { 21 | CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US"); 22 | 23 | Kick.Start(config => config 24 | .LogTo(_output.WriteLine) 25 | .IncludeAssemblyFor() 26 | .UseEntityChange() 27 | ); 28 | 29 | 30 | var original = new Order 31 | { 32 | Id = Guid.NewGuid().ToString(), 33 | OrderNumber = 1000, 34 | Total = 10000, 35 | }; 36 | 37 | var current = new Order 38 | { 39 | Id = Guid.NewGuid().ToString(), 40 | OrderNumber = 1000, 41 | Total = 11000, 42 | Items = new List 43 | { 44 | new OrderLine { Sku = "abc-123", Quanity = 1, UnitPrice = 5000 }, 45 | } 46 | }; 47 | 48 | 49 | var comparer = new EntityComparer(); 50 | var changes = comparer.Compare(original, current); 51 | 52 | changes.Should().NotBeNull(); 53 | changes.Count.Should().Be(3); 54 | 55 | var total = changes.FirstOrDefault(c => c.Path == "Total"); 56 | total.Should().NotBeNull(); 57 | total.Path.Should().Be("Total"); 58 | total.CurrentFormatted.Should().Be("$11,000.00"); 59 | 60 | var items = changes.FirstOrDefault(c => c.Path == "Items[0]"); 61 | items.Should().NotBeNull(); 62 | items.Path.Should().Be("Items[0]"); 63 | items.CurrentFormatted.Should().Be("abc-123"); 64 | items.Operation.Should().Be(ChangeOperation.Add); 65 | 66 | 67 | WriteMarkdown(changes); 68 | } 69 | 70 | 71 | 72 | private void WriteMarkdown(IReadOnlyList changes) 73 | { 74 | var formatter = new MarkdownFormatter(); 75 | var markdown = formatter.Format(changes); 76 | 77 | _output.WriteLine(markdown); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /test/KickStart.Unity.Tests/UnityStarterTest.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | using Test.Core; 4 | 5 | using Unity; 6 | 7 | namespace KickStart.Unity.Tests; 8 | 9 | public class UnityStarterTest 10 | { 11 | private readonly ITestOutputHelper _output; 12 | 13 | public UnityStarterTest(ITestOutputHelper output) 14 | { 15 | _output = output; 16 | } 17 | 18 | [Fact] 19 | public void UseUnity() 20 | { 21 | Kick.Start(config => config 22 | .LogTo(_output.WriteLine) 23 | .IncludeAssemblyFor() 24 | .UseUnity() 25 | ); 26 | 27 | Kick.ServiceProvider.Should().NotBeNull(); 28 | Kick.ServiceProvider.Should().BeOfType(); 29 | 30 | var repo = Kick.ServiceProvider.GetService(); 31 | repo.Should().NotBeNull(); 32 | repo.Should().BeOfType(); 33 | } 34 | 35 | [Fact] 36 | public void UseUnityInitialize() 37 | { 38 | Kick.Start(config => config 39 | .LogTo(_output.WriteLine) 40 | .IncludeAssemblyFor() 41 | .UseUnity(c => c 42 | .Container(b => b.RegisterType()) 43 | ) 44 | ); 45 | 46 | Kick.ServiceProvider.Should().NotBeNull(); 47 | Kick.ServiceProvider.Should().BeOfType(); 48 | 49 | var repo = Kick.ServiceProvider.GetService(); 50 | repo.Should().NotBeNull(); 51 | repo.Should().BeOfType(); 52 | 53 | var employee = Kick.ServiceProvider.GetService(); 54 | employee.Should().NotBeNull(); 55 | } 56 | 57 | 58 | [Fact] 59 | public void UseServiceInitialize() 60 | { 61 | Kick.Start(config => config 62 | .LogTo(_output.WriteLine) 63 | .IncludeAssemblyFor() 64 | .UseUnity() 65 | ); 66 | 67 | Kick.ServiceProvider.Should().NotBeNull(); 68 | Kick.ServiceProvider.Should().BeOfType(); 69 | 70 | 71 | var userService = Kick.ServiceProvider.GetService(); 72 | userService.Should().NotBeNull(); 73 | userService.Connection.Should().NotBeNull(); 74 | userService.Connection.Should().BeOfType(); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/KickStart.SimpleInjector/SimpleInjectorBuilder.cs: -------------------------------------------------------------------------------- 1 | using SimpleInjector; 2 | 3 | namespace KickStart.SimpleInjector; 4 | 5 | /// 6 | /// SimpleInjector configuration builder 7 | /// 8 | public class SimpleInjectorBuilder : ISimpleInjectorBuilder 9 | { 10 | private readonly SimpleInjectorOptions _options; 11 | 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// The options. 16 | public SimpleInjectorBuilder(SimpleInjectorOptions options) 17 | { 18 | _options = options; 19 | } 20 | 21 | /// 22 | /// Sets the container accessor . Resolve services under this . 23 | /// 24 | /// The container accessor . 25 | /// 26 | public ISimpleInjectorBuilder Container(Action accessor) 27 | { 28 | _options.Accessor = accessor; 29 | return this; 30 | } 31 | 32 | /// 33 | /// Sets the creator . 34 | /// 35 | /// The creator. 36 | /// 37 | public ISimpleInjectorBuilder Creator(Func creator) 38 | { 39 | _options.Creator = creator; 40 | return this; 41 | } 42 | 43 | /// 44 | /// Sets the initialize container . Register services under this . 45 | /// 46 | /// The initialize container . 47 | /// 48 | public ISimpleInjectorBuilder Initialize(Action initializer) 49 | { 50 | _options.Initializer = initializer; 51 | return this; 52 | } 53 | 54 | /// 55 | /// Verifies the Container with the specified . 56 | /// 57 | /// Specifies how the container should verify its configuration. 58 | /// 59 | public ISimpleInjectorBuilder Verify(VerificationOption? options) 60 | { 61 | _options.VerificationOption = options; 62 | return this; 63 | } 64 | } -------------------------------------------------------------------------------- /src/KickStart/Services/ServiceRegistrationBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// Service registration builder 5 | /// 6 | public class ServiceRegistrationBuilder : IServiceRegistrationBuilder 7 | { 8 | private readonly IEnumerable _types; 9 | private IEnumerable _concreteTypes; 10 | 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The current types to scan 15 | public ServiceRegistrationBuilder(IEnumerable types) 16 | { 17 | _types = types; 18 | } 19 | 20 | /// 21 | /// Gets a list of type maps to register. 22 | /// 23 | public List TypeMaps { get; private set; } 24 | 25 | 26 | /// 27 | /// Filters the types based on a . 28 | /// 29 | /// A function to test each element for a condition. 30 | /// An to build service registrations 31 | /// If the argument is null. 32 | public IServiceRegistrationBuilder Types(Action predicate) 33 | { 34 | if (predicate == null) 35 | throw new ArgumentNullException(nameof(predicate)); 36 | 37 | var typeFilter = new ConcreteTypeFilter(_types); 38 | predicate(typeFilter); 39 | _concreteTypes = typeFilter.FilteredTypes; 40 | 41 | return this; 42 | } 43 | 44 | /// 45 | /// Configure how the types should be registered as. 46 | /// 47 | /// A function to configure how types should be registered. 48 | /// An to build service registrations 49 | /// If the argument is null. 50 | public IServiceRegistrationBuilder As(Action mapper) 51 | { 52 | if (mapper == null) 53 | throw new ArgumentNullException(nameof(mapper)); 54 | 55 | var typeMapper = new ServiceTypeMapper(_concreteTypes); 56 | mapper(typeMapper); 57 | TypeMaps = typeMapper.TypeMaps; 58 | 59 | return this; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/KickStart.SimpleInjector/SimpleInjectorStarter.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | using SimpleInjector; 4 | 5 | namespace KickStart.SimpleInjector; 6 | 7 | /// 8 | /// SimpleInjector KickStarter extension 9 | /// 10 | /// 11 | public class SimpleInjectorStarter : IKickStarter 12 | { 13 | private readonly SimpleInjectorOptions _options; 14 | 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | /// The options. 19 | public SimpleInjectorStarter(SimpleInjectorOptions options) 20 | { 21 | _options = options; 22 | } 23 | 24 | /// 25 | /// Runs the application KickStart extension with specified . 26 | /// 27 | /// The KickStart containing assemblies to scan. 28 | public void Run(Context context) 29 | { 30 | var container = _options?.Creator() ?? new Container(); 31 | 32 | // must run first to allow settings options 33 | _options?.Initializer?.Invoke(container); 34 | 35 | RegisterSimpleInjector(context, container); 36 | RegisterServiceModule(context, container); 37 | 38 | if (_options.VerificationOption.HasValue) 39 | container.Verify(_options.VerificationOption.Value); 40 | 41 | _options.Accessor?.Invoke(container); 42 | 43 | context.SetServiceProvider(container); 44 | } 45 | 46 | 47 | private void RegisterSimpleInjector(Context context, Container container) 48 | { 49 | var modules = context.GetInstancesAssignableFrom(); 50 | foreach (var module in modules) 51 | { 52 | context.WriteLog("Register SimpleInjector Module: {0}", module); 53 | 54 | module.Register(container, context.Data); 55 | } 56 | } 57 | 58 | private void RegisterServiceModule(Context context, Container container) 59 | { 60 | var wrapper = new SimpleInjectorRegistration(context, container); 61 | var modules = context.GetInstancesAssignableFrom(); 62 | foreach (var module in modules) 63 | { 64 | context.WriteLog("Register Service Module: {0}", module); 65 | 66 | module.Register(wrapper, context.Data); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /test/KickStart.AutoMapper.Tests/AutoMapperKickerTest.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.AutoMapper.Tests; 6 | 7 | 8 | public class AutoMapperKickerTest 9 | { 10 | private readonly ITestOutputHelper _output; 11 | 12 | public AutoMapperKickerTest(ITestOutputHelper output) 13 | { 14 | _output = output; 15 | } 16 | 17 | [Fact] 18 | public void ConfigureBasic() 19 | { 20 | Kick.Start(config => config 21 | .LogTo(_output.WriteLine) 22 | .IncludeAssemblyFor() 23 | .UseAutoMapper() 24 | ); 25 | 26 | Kick.Data.TryGetValue(AutoMapperStarter.AutoMapperConfiguration, out var value); 27 | 28 | var configuration = value as IConfigurationProvider; 29 | configuration.Should().NotBeNull(); 30 | 31 | var employee = new Employee 32 | { 33 | FirstName = "Test", 34 | LastName = "User", 35 | EmailAddress = "test.user@email.com", 36 | SysVersion = BitConverter.GetBytes(8) 37 | }; 38 | 39 | var mapper = configuration.CreateMapper(); 40 | mapper.Should().NotBeNull(); 41 | 42 | var user = mapper.Map(employee); 43 | user.Should().NotBeNull(); 44 | user.EmailAddress.Should().Be(employee.EmailAddress); 45 | user.SysVersion.Should().NotBeNull(); 46 | } 47 | 48 | [Fact] 49 | public void ConfigureFull() 50 | { 51 | Kick.Start(config => config 52 | .LogTo(_output.WriteLine) 53 | .IncludeAssemblyFor() 54 | .UseAutoMapper(c => c 55 | .Validate() 56 | ) 57 | ); 58 | 59 | Kick.Data.TryGetValue(AutoMapperStarter.AutoMapperConfiguration, out var value); 60 | 61 | var configuration = value as IConfigurationProvider; 62 | configuration.Should().NotBeNull(); 63 | 64 | var employee = new Employee 65 | { 66 | FirstName = "Test", 67 | LastName = "User", 68 | EmailAddress = "test.user@email.com", 69 | SysVersion = BitConverter.GetBytes(8) 70 | }; 71 | 72 | var mapper = configuration.CreateMapper(); 73 | mapper.Should().NotBeNull(); 74 | 75 | var user = mapper.Map(employee); 76 | user.Should().NotBeNull(); 77 | user.EmailAddress.Should().Be(employee.EmailAddress); 78 | 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/KickStart/Services/IConcreteTypeFilter.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// An to filter service types 5 | /// 6 | public interface IConcreteTypeFilter 7 | { 8 | /// 9 | /// Filter to types that are assignable to . 10 | /// 11 | /// The type that should be assignable. 12 | /// An to filter service types 13 | IConcreteTypeFilter AssignableTo(); 14 | 15 | /// 16 | /// Filter to types that are assignable to the specified . 17 | /// 18 | /// The type that should be assignable. 19 | /// An to filter service types 20 | /// If the argument is null. 21 | IConcreteTypeFilter AssignableTo(Type type); 22 | 23 | /// 24 | /// Filter to types that are assignable to any of the specified . 25 | /// 26 | /// >The types that should be assignable. 27 | /// An to filter service types 28 | /// If the argument is null. 29 | IConcreteTypeFilter AssignableToAny(params Type[] types); 30 | 31 | /// 32 | /// Filter to types that are assignable to any of the specified . 33 | /// 34 | /// >The types that should be assignable. 35 | /// An to filter service types 36 | /// If the argument is null. 37 | IConcreteTypeFilter AssignableToAny(IEnumerable types); 38 | 39 | /// 40 | /// Filter types based on the specified . 41 | /// 42 | /// The predicate to filter types. 43 | /// An to filter service types 44 | /// If the argument is null. 45 | IConcreteTypeFilter Where(Func predicate); 46 | } -------------------------------------------------------------------------------- /src/KickStart/Services/ServiceRegistrationBase.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// Base class for 5 | /// 6 | public abstract class ServiceRegistrationBase : IServiceRegistration 7 | { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | /// The current service . 12 | protected ServiceRegistrationBase(Context serviceContext) 13 | { 14 | ServiceContext = serviceContext ?? throw new ArgumentNullException(nameof(serviceContext)); 15 | } 16 | 17 | /// 18 | /// Gets the current service . 19 | /// 20 | /// The current service 21 | public Context ServiceContext { get; } 22 | 23 | /// 24 | /// Registers a service of the type specified in with an 25 | /// implementation of the type specified in using 26 | /// the specified . 27 | /// 28 | /// The type of the service to register. 29 | /// The implementation type of the service. 30 | /// The service lifetime. 31 | /// 32 | /// A reference to this instance after the operation has completed. 33 | /// 34 | public abstract IServiceRegistration Register(Type serviceType, Type implementationType, ServiceLifetime lifetime); 35 | 36 | /// 37 | /// Registers a service of the type specified in with a 38 | /// factory specified in using 39 | /// the specified . 40 | /// 41 | /// The type of the service to register. 42 | /// The factory that creates the service. 43 | /// The service lifetime. 44 | /// 45 | /// A reference to this instance after the operation has completed. 46 | /// 47 | /// 48 | public abstract IServiceRegistration Register(Type serviceType, Func implementationFactory, ServiceLifetime lifetime); 49 | } -------------------------------------------------------------------------------- /src/KickStart/StartupTask/StartupTaskExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart.StartupTask; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace KickStart; 5 | 6 | /// 7 | /// Extension methods to use configure startup tasks 8 | /// 9 | public static class StartupTaskExtensions 10 | { 11 | /// 12 | /// Use the startup task extension to execute all instances of . 13 | /// 14 | /// The configuration builder. 15 | /// 16 | /// A fluent to configure startup tasks 17 | /// 18 | /// Configure KickStart to use startup tasks 19 | /// config 21 | /// .IncludeAssemblyFor() 22 | /// .UseStartupTask() 23 | /// .LogLevel(TraceLevel.Verbose) 24 | /// );]]> 25 | /// 26 | public static IConfigurationBuilder UseStartupTask(this IConfigurationBuilder configurationBuilder) 27 | { 28 | return UseStartupTask(configurationBuilder, null); 29 | } 30 | 31 | /// 32 | /// Use the startup task extension to execute all instances of . 33 | /// 34 | /// The configuration builder. 35 | /// The to configure StartupTask options. 36 | /// 37 | /// A fluent to configure startup tasks 38 | /// 39 | /// Configure KickStart to use startup tasks using Autofac container to resolve instances. 40 | /// config 42 | /// .IncludeAssemblyFor() 43 | /// .UseAutofac() 44 | /// .UseStartupTask(c => c.UseContainer()) 45 | /// .LogLevel(TraceLevel.Verbose) 46 | /// );]]> 47 | /// 48 | public static IConfigurationBuilder UseStartupTask(this IConfigurationBuilder configurationBuilder, Action configure) 49 | { 50 | var options = new StartupTaskOptions(); 51 | var starter = new StartupTaskStarter(options); 52 | 53 | if (configure != null) 54 | { 55 | var builder = new StartupTaskBuilder(options); 56 | configure(builder); 57 | } 58 | 59 | configurationBuilder.Use(starter); 60 | 61 | return configurationBuilder; 62 | } 63 | } -------------------------------------------------------------------------------- /src/KickStart.DependencyInjection/DependencyInjectionStarter.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | 6 | namespace KickStart.DependencyInjection; 7 | 8 | /// 9 | /// Microsoft.Extensions.DependencyInjection KickStarter extension 10 | /// 11 | /// 12 | public class DependencyInjectionStarter : IKickStarter 13 | { 14 | private readonly DependencyInjectionOptions _options; 15 | 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// The options. 20 | public DependencyInjectionStarter(DependencyInjectionOptions options) 21 | { 22 | _options = options; 23 | } 24 | 25 | /// 26 | /// Runs the application KickStart extension with specified . 27 | /// 28 | /// The KickStart containing assemblies to scan. 29 | public void Run(Context context) 30 | { 31 | var serviceCollection = _options?.Creator() ?? new ServiceCollection(); 32 | 33 | _options?.Initializer?.Invoke(serviceCollection); 34 | 35 | RegisterDependencyInjection(context, serviceCollection); 36 | RegisterServiceModule(context, serviceCollection); 37 | 38 | var provider = serviceCollection.BuildServiceProvider(); 39 | 40 | _options?.Accessor?.Invoke(provider); 41 | 42 | context.SetServiceProvider(provider); 43 | } 44 | 45 | 46 | private void RegisterDependencyInjection(Context context, IServiceCollection serviceCollection) 47 | { 48 | var modules = context.GetInstancesAssignableFrom(); 49 | foreach (var module in modules) 50 | { 51 | context.WriteLog("Register DependencyInjection Module: {0}", module); 52 | 53 | module.Register(serviceCollection, context.Data); 54 | } 55 | } 56 | 57 | private void RegisterServiceModule(Context context, IServiceCollection serviceCollection) 58 | { 59 | var wrapper = new DependencyInjectionRegistration(context, serviceCollection); 60 | var modules = context.GetInstancesAssignableFrom(); 61 | foreach (var module in modules) 62 | { 63 | context.WriteLog("Register Service Module: {0}", module); 64 | 65 | module.Register(wrapper, context.Data); 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/KickStart.AutoMapper/AutoMapperExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart.AutoMapper; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace KickStart; 5 | 6 | /// 7 | /// KickStart Extension for AutoMapper. 8 | /// 9 | public static class AutoMapperExtensions 10 | { 11 | /// 12 | /// Use the KickStart extension to configure AutoMapper. 13 | /// 14 | /// The configuration builder. 15 | /// 16 | /// A fluent to configure KickStart. 17 | /// 18 | /// Configure AutoMapper on application startup 19 | /// config 21 | /// .IncludeAssemblyFor() 22 | /// .UseAutoMapper() 23 | /// .LogLevel(TraceLevel.Verbose) 24 | /// );]]> 25 | /// 26 | public static IConfigurationBuilder UseAutoMapper(this IConfigurationBuilder configurationBuilder) 27 | { 28 | return UseAutoMapper(configurationBuilder, null); 29 | } 30 | 31 | /// 32 | /// Use the KickStart extension to configure AutoMapper. 33 | /// 34 | /// The configuration builder. 35 | /// The to configure AutoMapper options. 36 | /// 37 | /// A fluent to configure KickStart. 38 | /// 39 | /// Configure AutoMapper on application startup 40 | /// config 42 | /// .IncludeAssemblyFor() 43 | /// .UseAutoMapper(c => c 44 | /// .Validate() 45 | /// .Initialize(map => map.AddGlobalIgnore("SysVersion")) 46 | /// ) 47 | /// .LogLevel(TraceLevel.Verbose) 48 | /// );]]> 49 | /// 50 | public static IConfigurationBuilder UseAutoMapper(this IConfigurationBuilder configurationBuilder, Action configure) 51 | { 52 | var options = new AutoMapperOptions(); 53 | var service = new AutoMapperStarter(options); 54 | 55 | if (configure != null) 56 | { 57 | var builder = new AutoMapperBuilder(options); 58 | configure(builder); 59 | } 60 | 61 | configurationBuilder.ExcludeAssemblyFor(); 62 | configurationBuilder.ExcludeAssemblyFor(); 63 | configurationBuilder.Use(service); 64 | 65 | return configurationBuilder; 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /src/KickStart/Services/ServiceProviderExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace KickStart.Services; 2 | 3 | /// 4 | /// Extension methods for getting services from an . 5 | /// 6 | public static class ServiceProviderExtensions 7 | { 8 | /// 9 | /// Get service of type from the . 10 | /// 11 | /// The type of service object to get. 12 | /// The to retrieve the service object from. 13 | /// A service object of type or null if there is no such service. 14 | public static T GetService(this IServiceProvider provider) 15 | { 16 | if (provider == null) 17 | throw new ArgumentNullException(nameof(provider)); 18 | 19 | return (T)provider.GetService(typeof(T)); 20 | } 21 | 22 | /// 23 | /// Get an enumeration of services of type from the . 24 | /// 25 | /// The type of service object to get. 26 | /// The to retrieve the services from. 27 | /// An enumeration of services of type . 28 | public static IEnumerable GetServices(this IServiceProvider provider) 29 | { 30 | if (provider == null) 31 | throw new ArgumentNullException(nameof(provider)); 32 | 33 | return provider.GetService>(); 34 | } 35 | 36 | /// 37 | /// Get an enumeration of services of type from the . 38 | /// 39 | /// The to retrieve the services from. 40 | /// An object that specifies the type of service object to get. 41 | /// An enumeration of services of type . 42 | public static IEnumerable GetServices(this IServiceProvider provider, Type serviceType) 43 | { 44 | if (provider == null) 45 | throw new ArgumentNullException(nameof(provider)); 46 | 47 | if (serviceType == null) 48 | throw new ArgumentNullException(nameof(serviceType)); 49 | 50 | var genericEnumerable = typeof(IEnumerable<>).MakeGenericType(serviceType); 51 | return (IEnumerable)provider.GetService(genericEnumerable); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /src/KickStart/Kick.cs: -------------------------------------------------------------------------------- 1 | #if PORTABLE 2 | using Stopwatch = KickStart.Portability.Stopwatch; 3 | #else 4 | using Stopwatch = System.Diagnostics.Stopwatch; 5 | #endif 6 | 7 | namespace KickStart; 8 | 9 | /// 10 | /// Initialize an application at startup using the KickStart extensions. 11 | /// 12 | public static class Kick 13 | { 14 | /// 15 | /// Gets a common IoC container that can be used in KickStart extensions. 16 | /// 17 | /// 18 | /// The common IoC container. 19 | /// 20 | public static IServiceProvider ServiceProvider { get; private set; } 21 | 22 | /// 23 | /// Gets the configuration data used for startup. 24 | /// 25 | /// 26 | /// The configuration data used for startup. 27 | /// 28 | public static IDictionary Data { get; private set; } 29 | 30 | /// 31 | /// Configure and run the KickStart extensions. 32 | /// 33 | /// The to configure KickStart before execution of the extensions. 34 | /// Configure KickStart to use startup tasks using Autofac container to resolve instances. 35 | /// config 37 | /// .IncludeAssemblyFor() 38 | /// .UseAutofac() 39 | /// .UseStartupTask(c => c.UseContainer()) 40 | /// .LogLevel(TraceLevel.Verbose) 41 | /// );]]> 42 | /// 43 | public static void Start(Action configurator) 44 | { 45 | if (configurator == null) 46 | throw new ArgumentNullException(nameof(configurator)); 47 | 48 | var config = new Configuration(); 49 | var builder = new ConfigurationBuilder(config); 50 | 51 | configurator(builder); 52 | 53 | var assemblies = config.Assemblies.Resolve(); 54 | 55 | // cache types 56 | var types = assemblies 57 | .SelectMany(a => a.GetLoadableTypes()) 58 | .ToList(); 59 | 60 | var context = new Context(types, config.Data, config.LogWriter); 61 | 62 | foreach (var starter in config.Starters) 63 | { 64 | context.WriteLog("Execute Starter: {0}", starter); 65 | 66 | var watch = Stopwatch.StartNew(); 67 | 68 | starter.Run(context); 69 | 70 | watch.Stop(); 71 | 72 | context.WriteLog("Completed Starter: {0}, Time: {1} ms", starter, watch.ElapsedMilliseconds); 73 | } 74 | 75 | // save service provider 76 | ServiceProvider = context.ServiceProvider; 77 | Data = context.Data; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/KickStart.EntityChange/EntityChangeExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart.EntityChange; 2 | 3 | // ReSharper disable once CheckNamespace 4 | namespace KickStart; 5 | 6 | /// 7 | /// KickStart Extension for EntityChange. 8 | /// 9 | public static class EntityChangeExtensions 10 | { 11 | /// 12 | /// Use the KickStart extension to configure EntityChange. 13 | /// 14 | /// The configuration builder. 15 | /// 16 | /// A fluent to configure KickStart. 17 | /// 18 | /// Configure EntityChange on application startup 19 | /// config 21 | /// .IncludeAssemblyFor() 22 | /// .UseEntityChange() 23 | /// .LogLevel(TraceLevel.Verbose) 24 | /// );]]> 25 | /// 26 | public static IConfigurationBuilder UseEntityChange(this IConfigurationBuilder configurationBuilder) 27 | { 28 | return UseEntityChange(configurationBuilder, null); 29 | } 30 | 31 | /// 32 | /// Use the KickStart extension to configure EntityChange. 33 | /// 34 | /// The configuration builder. 35 | /// The to configure EntityChange options. 36 | /// 37 | /// A fluent to configure KickStart. 38 | /// 39 | /// Configure EntityChange on application startup 40 | /// config 42 | /// .IncludeAssemblyFor() 43 | /// .UseEntityChange(c => c 44 | /// .Configure(config => 45 | /// { 46 | /// config.Entity(e => 47 | /// { 48 | /// e.Property(p => p.Total).Formatter(StringFormatter.Currency); 49 | /// }); 50 | /// }); 51 | /// ) 52 | /// .LogLevel(TraceLevel.Verbose) 53 | /// );]]> 54 | /// 55 | public static IConfigurationBuilder UseEntityChange(this IConfigurationBuilder configurationBuilder, Action configure) 56 | { 57 | var options = new EntityChangeOptions(); 58 | var service = new EntityChangeStarter(options); 59 | 60 | if (configure != null) 61 | { 62 | var builder = new EntityChangeBuilder(options); 63 | configure(builder); 64 | } 65 | 66 | configurationBuilder.ExcludeAssemblyFor(); 67 | configurationBuilder.ExcludeAssemblyFor(); 68 | configurationBuilder.Use(service); 69 | 70 | return configurationBuilder; 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /src/KickStart.DependencyInjection/DependencyInjectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using KickStart.DependencyInjection; 2 | 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | 6 | // ReSharper disable once CheckNamespace 7 | namespace KickStart; 8 | 9 | /// 10 | /// KickStart Extension for Microsoft.Extensions.DependencyInjection. 11 | /// 12 | public static class DependencyInjectionExtensions 13 | { 14 | /// 15 | /// Use the KickStart extension to configure Microsoft.Extensions.DependencyInjection. 16 | /// 17 | /// The configuration builder. 18 | /// 19 | /// A fluent to configure KickStart. 20 | /// 21 | public static IConfigurationBuilder UseDependencyInjection(this IConfigurationBuilder configurationBuilder) 22 | { 23 | return UseDependencyInjection(configurationBuilder, c => c.Creator(() => new ServiceCollection())); 24 | } 25 | 26 | /// 27 | /// Use the KickStart extension to configure Microsoft.Extensions.DependencyInjection. 28 | /// 29 | /// The configuration builder. 30 | /// The initial service collection. 31 | /// 32 | /// A fluent to configure KickStart. 33 | /// 34 | public static IConfigurationBuilder UseDependencyInjection(this IConfigurationBuilder configurationBuilder, IServiceCollection collection) 35 | { 36 | return UseDependencyInjection(configurationBuilder, c => c.Creator(() => collection)); 37 | } 38 | 39 | /// 40 | /// Use the KickStart extension to configure Microsoft.Extensions.DependencyInjection. 41 | /// 42 | /// The configuration builder. 43 | /// The to configure DependencyInjection options. 44 | /// 45 | /// A fluent to configure KickStart. 46 | /// 47 | public static IConfigurationBuilder UseDependencyInjection(this IConfigurationBuilder configurationBuilder, Action configure) 48 | { 49 | var options = new DependencyInjectionOptions(); 50 | var starter = new DependencyInjectionStarter(options); 51 | 52 | if (configure != null) 53 | { 54 | var builder = new DependencyInjectionBuilder(options); 55 | configure(builder); 56 | } 57 | 58 | configurationBuilder.ExcludeAssemblyFor(); 59 | configurationBuilder.ExcludeAssemblyFor(); 60 | configurationBuilder.Use(starter); 61 | 62 | return configurationBuilder; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/KickStart.Unity/UnityServiceRegistration.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | using Unity; 4 | using Unity.Lifetime; 5 | 6 | namespace KickStart.Unity; 7 | 8 | /// 9 | /// Unity implementation for . 10 | /// 11 | /// 12 | public class UnityServiceRegistration : ServiceRegistrationBase 13 | { 14 | private readonly IUnityContainer _container; 15 | 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// The container. 20 | /// The current service . 21 | public UnityServiceRegistration(Context serviceContext, IUnityContainer container) : base(serviceContext) 22 | { 23 | _container = container; 24 | } 25 | 26 | /// 27 | /// Registers a service of the type specified in with an 28 | /// implementation of the type specified in using 29 | /// the specified . 30 | /// 31 | /// The type of the service to register. 32 | /// The implementation type of the service. 33 | /// The service lifetime. 34 | /// 35 | /// A reference to this instance after the operation has completed. 36 | /// 37 | public override IServiceRegistration Register(Type serviceType, Type implementationType, ServiceLifetime lifetime) 38 | { 39 | var lifetimeManager = lifetime == ServiceLifetime.Singleton ? new ContainerControlledLifetimeManager() : null; 40 | _container.RegisterType(serviceType, implementationType, lifetimeManager); 41 | 42 | return this; 43 | } 44 | 45 | /// 46 | /// Registers a service of the type specified in with a 47 | /// factory specified in using 48 | /// the specified . 49 | /// 50 | /// The type of the service to register. 51 | /// The factory that creates the service. 52 | /// The service lifetime. 53 | /// 54 | /// A reference to this instance after the operation has completed. 55 | /// 56 | /// 57 | /// Not supported. 58 | public override IServiceRegistration Register(Type serviceType, Func implementationFactory, ServiceLifetime lifetime) 59 | { 60 | throw new NotSupportedException(); 61 | } 62 | } -------------------------------------------------------------------------------- /docs/configuration.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | KickStart uses a fluent configuration model. To start configuration, use the `Kick.Start` delegate. 4 | 5 | ## Example 6 | 7 | This example will scan the assembly containing UserModule. Then it will find all Autofac modules and register them with Autofac. Then, all AutoMapper profiles will be registered with AutoMapper. Finally, it will find all classes that implement `IStartupTask` and run it. 8 | 9 | ```csharp 10 | Kick.Start(config => config 11 | .IncludeAssemblyFor() 12 | .UseAutofac() 13 | .UseAutoMapper() 14 | .UseStartupTask() 15 | ); 16 | ``` 17 | 18 | ## Logging 19 | 20 | Output KickStart logs using the `LogTo` fluent configuration 21 | 22 | Write all logs to Console 23 | 24 | ```csharp 25 | Kick.Start(config => config 26 | .LogTo(Console.WriteLine) 27 | ); 28 | ``` 29 | 30 | Write all logs to NLog 31 | 32 | ```csharp 33 | public class Startup 34 | { 35 | private static NLog.Logger _logger = NLog.LogManager.GetLogger("Startup"); 36 | 37 | public Startup(ITestOutputHelper output) 38 | { 39 | Kick.Start(config => config 40 | .LogTo(_logger.Debug) 41 | ); 42 | } 43 | } 44 | ``` 45 | 46 | Write all logs to xUnit 47 | 48 | ```csharp 49 | public class UnitTest 50 | { 51 | private readonly ITestOutputHelper _output; 52 | 53 | public UnitTest(ITestOutputHelper output) 54 | { 55 | _output = output; 56 | } 57 | 58 | [Fact] 59 | public void Configure() 60 | { 61 | Kick.Start(config => config 62 | .LogTo(_output.WriteLine) 63 | ); 64 | } 65 | } 66 | ``` 67 | 68 | ## Assembly Scanning 69 | 70 | KickStart uses assembly scanning to look for a particular type when a startup task is run. The following examples are how to configure which assemblies to scan. If no assemblies are configured, the default behaviour is to scan all loaded assemblies. 71 | 72 | Include Assembly containing particular type. 73 | 74 | ```csharp 75 | Kick.Start(config => config 76 | .IncludeAssemblyFor() 77 | ); 78 | ``` 79 | 80 | Include the assemblies that contain the specified name. 81 | 82 | ```csharp 83 | Kick.Start(config => config 84 | .IncludeName("Project") 85 | ); 86 | ``` 87 | 88 | Exclude Assembly containing particular type. 89 | 90 | ```csharp 91 | Kick.Start(config => config 92 | .ExcludeAssemblyFor() 93 | ); 94 | ``` 95 | 96 | Exclude the assemblies that contain the specified name. 97 | 98 | ```csharp 99 | Kick.Start(config => config 100 | .ExcludeName("Microsoft") 101 | ); 102 | ``` 103 | 104 | ## Data Dictionary 105 | 106 | Pass data to the startup modules 107 | 108 | ```csharp 109 | Kick.Start(config => config 110 | .Data("environment", "debug") 111 | .Data(d => 112 | { 113 | d["key"] = 123; 114 | d["server"] = "master"; 115 | }) 116 | ); 117 | ``` 118 | -------------------------------------------------------------------------------- /src/KickStart/StartupTask/StartupTaskStarter.cs: -------------------------------------------------------------------------------- 1 | #if PORTABLE 2 | using Stopwatch = KickStart.Portability.Stopwatch; 3 | #else 4 | using Stopwatch = System.Diagnostics.Stopwatch; 5 | #endif 6 | 7 | namespace KickStart.StartupTask; 8 | 9 | /// 10 | /// A KickStart extension to run startup tasks on application start. 11 | /// 12 | public class StartupTaskStarter : IKickStarter 13 | { 14 | private readonly StartupTaskOptions _options; 15 | 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | /// The options. 20 | public StartupTaskStarter(StartupTaskOptions options) 21 | { 22 | _options = options; 23 | } 24 | 25 | /// 26 | /// Runs the application KickStart extension with specified . 27 | /// 28 | /// The KickStart containing assemblies to scan. 29 | public void Run(Context context) 30 | { 31 | RunAsynchronousTask(context); 32 | RunActions(context); 33 | } 34 | 35 | private void RunActions(Context context) 36 | { 37 | var watch = Stopwatch.StartNew(); 38 | foreach (var startupTask in _options.Actions) 39 | { 40 | context.WriteLog("Execute Startup Action"); 41 | 42 | watch.Restart(); 43 | startupTask.Invoke(context.ServiceProvider, context.Data); 44 | watch.Stop(); 45 | 46 | context.WriteLog("Complete Startup Action; Time: {0} ms", watch.ElapsedMilliseconds); 47 | } 48 | watch.Stop(); 49 | } 50 | 51 | private void RunAsynchronousTask(Context context) 52 | { 53 | // order and group by priority 54 | var startupGroups = context.GetInstancesAssignableFrom() 55 | .OrderBy(t => t.Priority) 56 | .GroupBy(p => p.Priority); 57 | 58 | 59 | // each priority group is run in parallel 60 | foreach (var startGroup in startupGroups) 61 | { 62 | context.WriteLog("Execute Startup Tasks; Priority: '{0}'", startGroup.Key); 63 | 64 | // start all tasts for this priority 65 | var tasks = startGroup 66 | .Select(startTask => RunTaskAsync(context, startTask)) 67 | .ToArray(); 68 | 69 | // wait till all done before starting next priority 70 | Task.WaitAll(tasks); 71 | } 72 | } 73 | 74 | private Task RunTaskAsync(Context context, IStartupTask startupTask) 75 | { 76 | var watch = Stopwatch.StartNew(); 77 | context.WriteLog("Execute Startup Task; Type: '{0}'", startupTask); 78 | 79 | return startupTask.RunAsync(context.Data) 80 | .ContinueWith(t => 81 | { 82 | watch.Stop(); 83 | context.WriteLog("Complete Startup Task; Type: '{0}', Time: {1} ms", startupTask, watch.ElapsedMilliseconds); 84 | }); 85 | } 86 | } -------------------------------------------------------------------------------- /src/KickStart.SimpleInjector/SimpleInjectorRegistration.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | using SimpleInjector; 4 | 5 | namespace KickStart.SimpleInjector; 6 | 7 | /// 8 | /// SimpleInjector implementation for . 9 | /// 10 | /// 11 | public class SimpleInjectorRegistration : ServiceRegistrationBase 12 | { 13 | private readonly Container _container; 14 | 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | /// The container. 19 | /// The current service . 20 | public SimpleInjectorRegistration(Context serviceContext, Container container) : base(serviceContext) 21 | { 22 | _container = container; 23 | } 24 | 25 | /// 26 | /// Registers a service of the type specified in with an 27 | /// implementation of the type specified in using 28 | /// the specified . 29 | /// 30 | /// The type of the service to register. 31 | /// The implementation type of the service. 32 | /// The service lifetime. 33 | /// 34 | /// A reference to this instance after the operation has completed. 35 | /// 36 | public override IServiceRegistration Register(Type serviceType, Type implementationType, ServiceLifetime lifetime) 37 | { 38 | if (lifetime == ServiceLifetime.Singleton) 39 | _container.RegisterSingleton(serviceType, implementationType); 40 | else 41 | _container.Register(serviceType, implementationType); 42 | 43 | return this; 44 | } 45 | 46 | /// 47 | /// Registers a service of the type specified in with a 48 | /// factory specified in using 49 | /// the specified . 50 | /// 51 | /// The type of the service to register. 52 | /// The factory that creates the service. 53 | /// The service lifetime. 54 | /// 55 | /// A reference to this instance after the operation has completed. 56 | /// 57 | /// 58 | public override IServiceRegistration Register(Type serviceType, Func implementationFactory, ServiceLifetime lifetime) 59 | { 60 | if (lifetime == ServiceLifetime.Singleton) 61 | _container.RegisterSingleton(serviceType, () => implementationFactory(_container)); 62 | else 63 | _container.Register(serviceType, () => implementationFactory(_container)); 64 | 65 | return this; 66 | } 67 | } -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | Application start-up helper to initialize things like an IoC container, register mapping information or run a task. 4 | 5 | [![Build status](https://github.com/loresoft/KickStart/workflows/Build/badge.svg)](https://github.com/loresoft/KickStart/actions) 6 | 7 | [![Coverage Status](https://coveralls.io/repos/github/loresoft/KickStart/badge.svg?branch=master)](https://coveralls.io/github/loresoft/KickStart?branch=master) 8 | 9 | | Package | Version | 10 | | :--- | :--- | 11 | | [KickStart](https://www.nuget.org/packages/KickStart/) | [![KickStart](https://img.shields.io/nuget/v/KickStart.svg)](https://www.nuget.org/packages/KickStart/) | 12 | | [KickStart.Autofac](https://www.nuget.org/packages/KickStart.Autofac/) | [![KickStart.Autofac](https://img.shields.io/nuget/v/KickStart.Autofac.svg)](https://www.nuget.org/packages/KickStart.Autofac/) | 13 | | [KickStart.AutoMapper](https://www.nuget.org/packages/KickStart.AutoMapper/) | [![KickStart.AutoMapper](https://img.shields.io/nuget/v/KickStart.AutoMapper.svg)](https://www.nuget.org/packages/KickStart.AutoMapper/) | 14 | | [KickStart.DependencyInjection](https://www.nuget.org/packages/KickStart.DependencyInjection/) | [![KickStart.DependencyInjection](https://img.shields.io/nuget/v/KickStart.DependencyInjection.svg)](https://www.nuget.org/packages/KickStart.DependencyInjection/) | 15 | | [KickStart.MongoDB](https://www.nuget.org/packages/KickStart.MongoDB/) | [![KickStart.MongoDB](https://img.shields.io/nuget/v/KickStart.MongoDB.svg)](https://www.nuget.org/packages/KickStart.MongoDB/) | 16 | | [KickStart.Ninject](https://www.nuget.org/packages/KickStart.Ninject/) | [![KickStart.Ninject](https://img.shields.io/nuget/v/KickStart.Ninject.svg)](https://www.nuget.org/packages/KickStart.Ninject/) | 17 | | [KickStart.SimpleInjector](https://www.nuget.org/packages/KickStart.SimpleInjector/) | [![KickStart.SimpleInjector](https://img.shields.io/nuget/v/KickStart.SimpleInjector.svg)](https://www.nuget.org/packages/KickStart.SimpleInjector/) | 18 | | [KickStart.Unity](https://www.nuget.org/packages/KickStart.Unity/) | [![KickStart.Unity](https://img.shields.io/nuget/v/KickStart.Unity.svg)](https://www.nuget.org/packages/KickStart.Unity/) | 19 | 20 | ## Download 21 | 22 | The KickStart library is available on nuget.org via package name `KickStart`. 23 | 24 | To install KickStart, run the following command in the Package Manager Console 25 | 26 | PM> Install-Package KickStart 27 | 28 | More information about NuGet package available at 29 | 30 | 31 | ## Development Builds 32 | 33 | Development builds are available on the myget.org feed. A development build is promoted to the main NuGet feed when it's determined to be stable. 34 | 35 | In your Package Manager settings add the following package source for development builds: 36 | 37 | 38 | ## Features 39 | 40 | - Run tasks on application start-up 41 | - Extension model to add library specific start up tasks 42 | - Common IoC container adaptor based on `IServiceProvider` 43 | - Singleton instance of an application level IoC container `Kick.ServiceProvider` 44 | -------------------------------------------------------------------------------- /test/KickStart.Tests/AssemblyResolverTest.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.Tests; 6 | 7 | public class AssemblyResolverTest 8 | { 9 | private readonly ITestOutputHelper _output; 10 | 11 | public AssemblyResolverTest(ITestOutputHelper output) 12 | { 13 | _output = output; 14 | } 15 | 16 | #if !(PORTABLE || NETSTANDARD1_3 || NETSTANDARD1_5 || NETSTANDARD1_6 || NETCOREAPP1_0) 17 | [Fact] 18 | public void DefaultResolve() 19 | { 20 | 21 | var resolver = new AssemblyResolver(_output.WriteLine); 22 | resolver.Should().NotBeNull(); 23 | 24 | var assemblies = resolver.Resolve().ToList(); 25 | assemblies.Should().NotBeEmpty(); 26 | assemblies.Should().Contain(a => a.FullName.StartsWith("System")); 27 | 28 | } 29 | 30 | [Fact] 31 | public void ExcludeSystem() 32 | { 33 | var resolver = new AssemblyResolver(_output.WriteLine); 34 | resolver.Should().NotBeNull(); 35 | 36 | resolver.ExcludeName("System"); 37 | 38 | var assemblies = resolver.Resolve().ToList(); 39 | assemblies.Should().NotBeEmpty(); 40 | assemblies.Should().NotContain(a => a.FullName.StartsWith("System")); 41 | } 42 | #endif 43 | 44 | [Fact] 45 | public void SystemExplicit() 46 | { 47 | var resolver = new AssemblyResolver(_output.WriteLine); 48 | resolver.Should().NotBeNull(); 49 | 50 | // add a few defaults 51 | resolver.IncludeAssemblyFor(); 52 | resolver.IncludeAssemblyFor(); 53 | resolver.IncludeAssemblyFor(); 54 | resolver.IncludeAssemblyFor(); 55 | resolver.IncludeAssemblyFor(); 56 | 57 | 58 | var assemblies = resolver.Resolve().ToList(); 59 | assemblies.Should().NotBeEmpty(); 60 | assemblies.Should().Contain(a => a.FullName.StartsWith("System")); 61 | } 62 | 63 | [Fact] 64 | public void ExcludeSystemExplicit() 65 | { 66 | var resolver = new AssemblyResolver(_output.WriteLine); 67 | resolver.Should().NotBeNull(); 68 | 69 | // add a few defaults 70 | resolver.IncludeAssemblyFor(); 71 | resolver.IncludeAssemblyFor(); 72 | resolver.IncludeAssemblyFor(); 73 | resolver.IncludeAssemblyFor(); 74 | resolver.IncludeAssemblyFor(); 75 | 76 | resolver.ExcludeName("System"); 77 | 78 | var assemblies = resolver.Resolve().ToList(); 79 | assemblies.Should().NotBeEmpty(); 80 | assemblies.Should().NotContain(a => a.FullName.StartsWith("System")); 81 | } 82 | 83 | 84 | [Fact] 85 | public void IncludeAssemblyForTestCore() 86 | { 87 | var resolver = new AssemblyResolver(_output.WriteLine); 88 | resolver.Should().NotBeNull(); 89 | 90 | resolver.IncludeAssemblyFor(); 91 | 92 | var assemblies = resolver.Resolve().ToList(); 93 | assemblies.Should().NotBeEmpty(); 94 | assemblies.Count.Should().Be(1); 95 | assemblies.Should().Contain(a => a == typeof(SampleWorker).GetTypeInfo().Assembly); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /.github/workflows/dotnet.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | env: 4 | DOTNET_NOLOGO: true 5 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true 6 | BUILD_PATH: "${{github.workspace}}/artifacts" 7 | COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} 8 | 9 | on: 10 | push: 11 | branches: 12 | - master 13 | - develop 14 | tags: 15 | - "v*" 16 | paths-ignore: 17 | - "docs/**" 18 | - "mkdocs.yml" 19 | pull_request: 20 | branches: 21 | - master 22 | - develop 23 | 24 | jobs: 25 | build: 26 | runs-on: ubuntu-latest 27 | 28 | steps: 29 | - name: Checkout 30 | uses: actions/checkout@v6 31 | with: 32 | fetch-depth: 0 33 | 34 | - name: Install .NET 35 | uses: actions/setup-dotnet@v5 36 | with: 37 | dotnet-version: 9.0.x 38 | 39 | - name: Restore Dependencies 40 | run: dotnet restore 41 | 42 | - name: Build Solution 43 | run: dotnet build --no-restore --configuration Release 44 | 45 | - name: Run Test 46 | run: dotnet test --no-build --configuration Release --collect:"XPlat Code Coverage" --settings coverlet.runsettings 47 | 48 | - name: Report Coverage 49 | if: success() 50 | uses: coverallsapp/github-action@v2 51 | with: 52 | file: "${{github.workspace}}/test/*/TestResults/*/coverage.info" 53 | format: lcov 54 | 55 | - name: Create Packages 56 | if: success() && github.event_name != 'pull_request' 57 | run: dotnet pack --configuration Release --no-build --output "${{env.BUILD_PATH}}" 58 | 59 | - name: Upload Packages 60 | if: success() && github.event_name != 'pull_request' 61 | uses: actions/upload-artifact@v6 62 | with: 63 | name: packages 64 | path: "${{env.BUILD_PATH}}" 65 | 66 | deploy: 67 | runs-on: ubuntu-latest 68 | needs: build 69 | if: success() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) 70 | 71 | steps: 72 | - name: Download Artifact 73 | uses: actions/download-artifact@v5 74 | with: 75 | name: packages 76 | 77 | - name: Publish Packages GitHub 78 | run: | 79 | for package in $(find -name "*.nupkg"); do 80 | echo "${0##*/}": Pushing $package... 81 | dotnet nuget push $package --source https://nuget.pkg.github.com/loresoft/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate 82 | done 83 | 84 | - name: Publish Packages feedz 85 | run: | 86 | for package in $(find -name "*.nupkg"); do 87 | echo "${0##*/}": Pushing $package... 88 | dotnet nuget push $package --source https://f.feedz.io/loresoft/open/nuget/index.json --api-key ${{ secrets.FEEDDZ_KEY }} --skip-duplicate 89 | done 90 | 91 | - name: Publish Packages Nuget 92 | if: startsWith(github.ref, 'refs/tags/v') 93 | run: | 94 | for package in $(find -name "*.nupkg"); do 95 | echo "${0##*/}": Pushing $package... 96 | dotnet nuget push $package --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_KEY }} --skip-duplicate 97 | done 98 | -------------------------------------------------------------------------------- /docs/usage.md: -------------------------------------------------------------------------------- 1 | # Usage 2 | 3 | The following are some example usages of KickStart. 4 | 5 | ## ASP.NET Core 2.0 6 | 7 | ```csharp 8 | public class Startup 9 | { 10 | public Startup(IConfiguration configuration) 11 | { 12 | Configuration = configuration; 13 | } 14 | 15 | public IConfiguration Configuration { get; } 16 | 17 | // This method gets called by the runtime. Use this method to add services to the container. 18 | public void ConfigureServices(IServiceCollection services) 19 | { 20 | // this will auto register logging and run the DependencyInjection startup 21 | services.KickStart(c => c 22 | .IncludeAssemblyFor() // where to look 23 | .Data("configuration", Configuration) // pass configuration to all startup modules 24 | .Data("hostProcess", "web") // used for conditional registration 25 | .UseStartupTask() // run startup task 26 | ); 27 | } 28 | } 29 | ``` 30 | 31 | ## ASP.NET 32 | 33 | Use Autofac with ASP.NET MVC 34 | 35 | ```csharp 36 | Kick.Start(c => c 37 | .IncludeAssemblyFor() 38 | .UseAutofac(a => a 39 | .Initialize(b => b.RegisterControllers(typeof(MvcApplication).Assembly)) // register all controllers 40 | .Container(r => DependencyResolver.SetResolver(new AutofacDependencyResolver(r))) // set asp.net resolver 41 | ) 42 | .UseAutoMapper() 43 | .UseMongoDB() 44 | .UseStartupTask() 45 | ); 46 | ``` 47 | 48 | Using SimpleInjector with ASP.NET WebAPI 49 | 50 | ```csharp 51 | Kick.Start(c => c 52 | .LogTo(_logger.Debug) 53 | .IncludeAssemblyFor() 54 | .Data("hostProcess", "web") 55 | .UseSimpleInjector(s => s 56 | .Verify(VerificationOption.VerifyOnly) 57 | .Initialize(container => 58 | { 59 | container.Options.DefaultScopedLifestyle = new WebApiRequestLifestyle(); 60 | container.RegisterWebApiControllers(httpConfiguration); // register all controllers 61 | }) 62 | .Container(container => 63 | { 64 | httpConfiguration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); // set asp.net resolver 65 | }) 66 | ) 67 | .UseStartupTask() 68 | ); 69 | ``` 70 | 71 | ## xUnit 72 | 73 | Example of bootstraping and logging with xUnit tests. 74 | 75 | ```csharp 76 | public class StartupTaskStarterTest 77 | { 78 | private readonly ITestOutputHelper _output; 79 | 80 | public StartupTaskStarterTest(ITestOutputHelper output) 81 | { 82 | _output = output; 83 | 84 | // bootstrap project 85 | Kick.Start(config => config 86 | .LogTo(_output.WriteLine) 87 | .Data("environment", "test") // pass data for conditional registration 88 | .IncludeAssemblyFor() 89 | .UseSimpleInjector () // initialize SimpleInjector 90 | .UseStartupTask() 91 | ); 92 | 93 | } 94 | 95 | [Fact] 96 | public void RunTest() 97 | { 98 | var userRepository = Kick.ServiceProvider.GetService(); 99 | Assert.NotNull(userRepository); 100 | 101 | // more tests 102 | } 103 | } 104 | ``` -------------------------------------------------------------------------------- /test/KickStart.DependencyInjection.Tests/DependencyInjectionrStarterTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | using Test.Core; 4 | 5 | namespace KickStart.DependencyInjection.Tests; 6 | 7 | public class DependencyInjectionStarterTest 8 | { 9 | private readonly ITestOutputHelper _output; 10 | 11 | public DependencyInjectionStarterTest(ITestOutputHelper output) 12 | { 13 | _output = output; 14 | } 15 | 16 | [Fact] 17 | public void UseDependencyInjection() 18 | { 19 | Kick.Start(config => config 20 | .LogTo(_output.WriteLine) 21 | .IncludeAssemblyFor() 22 | .UseDependencyInjection() 23 | ); 24 | 25 | Kick.ServiceProvider.Should().NotBeNull(); 26 | 27 | var repo = Kick.ServiceProvider.GetService(); 28 | repo.Should().NotBeNull(); 29 | repo.Should().BeOfType(); 30 | } 31 | 32 | [Fact] 33 | public void UseDependencyInjectionInitialize() 34 | { 35 | Kick.Start(config => config 36 | .LogTo(_output.WriteLine) 37 | .IncludeAssemblyFor() 38 | .UseDependencyInjection(c => c 39 | .Initialize(b => b.AddTransient()) 40 | ) 41 | ); 42 | 43 | Kick.ServiceProvider.Should().NotBeNull(); 44 | 45 | var repo = Kick.ServiceProvider.GetService(); 46 | repo.Should().NotBeNull(); 47 | repo.Should().BeOfType(); 48 | 49 | var employee = Kick.ServiceProvider.GetService(); 50 | employee.Should().NotBeNull(); 51 | } 52 | 53 | 54 | [Fact] 55 | public void UseServiceInitialize() 56 | { 57 | Kick.Start(config => config 58 | .LogTo(_output.WriteLine) 59 | .IncludeAssemblyFor() 60 | .IncludeAssemblyFor() 61 | .UseDependencyInjection() 62 | ); 63 | 64 | Kick.ServiceProvider.Should().NotBeNull(); 65 | 66 | var userRepository = Kick.ServiceProvider.GetService(); 67 | userRepository.Should().NotBeNull(); 68 | userRepository.Should().BeOfType(); 69 | 70 | var employeeRepository = Kick.ServiceProvider.GetService>(); 71 | employeeRepository.Should().NotBeNull(); 72 | employeeRepository.Should().BeOfType(); 73 | 74 | var userService = Kick.ServiceProvider.GetService(); 75 | userService.Should().NotBeNull(); 76 | userService.Connection.Should().NotBeNull(); 77 | userService.Connection.Should().BeOfType(); 78 | 79 | 80 | var vehicleService = Kick.ServiceProvider.GetService(); 81 | vehicleService.Should().NotBeNull(); 82 | vehicleService.Should().BeOfType(); 83 | 84 | var minivanService = Kick.ServiceProvider.GetService(); 85 | minivanService.Should().NotBeNull(); 86 | minivanService.Should().BeOfType(); 87 | 88 | var services = Kick.ServiceProvider.GetServices().ToList(); 89 | services.Should().NotBeNull(); 90 | services.Should().NotBeEmpty(); 91 | services.Count.Should().Be(3); 92 | } 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/KickStart.Autofac/AutofacServiceRegistration.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | 3 | using KickStart.Services; 4 | 5 | namespace KickStart.Autofac; 6 | 7 | /// 8 | /// Autofac implementation for . 9 | /// 10 | /// 11 | public class AutofacServiceRegistration : ServiceRegistrationBase 12 | { 13 | private readonly ContainerBuilder _container; 14 | 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | /// The container. 19 | /// The current service . 20 | public AutofacServiceRegistration(Context serviceContext, ContainerBuilder container) : base(serviceContext) 21 | { 22 | _container = container; 23 | } 24 | 25 | /// 26 | /// Registers a service of the type specified in with an 27 | /// implementation of the type specified in using 28 | /// the specified . 29 | /// 30 | /// The type of the service to register. 31 | /// The implementation type of the service. 32 | /// The service lifetime. 33 | /// 34 | /// A reference to this instance after the operation has completed. 35 | /// 36 | public override IServiceRegistration Register(Type serviceType, Type implementationType, ServiceLifetime lifetime) 37 | { 38 | 39 | var builder = _container 40 | .RegisterType(implementationType) 41 | .As(serviceType); 42 | 43 | 44 | if (lifetime == ServiceLifetime.Singleton) 45 | builder.SingleInstance(); 46 | else if (lifetime == ServiceLifetime.Scoped) 47 | builder.InstancePerLifetimeScope(); 48 | 49 | return this; 50 | } 51 | 52 | /// 53 | /// Registers a service of the type specified in with a 54 | /// factory specified in using 55 | /// the specified . 56 | /// 57 | /// The type of the service to register. 58 | /// The factory that creates the service. 59 | /// The service lifetime. 60 | /// 61 | /// A reference to this instance after the operation has completed. 62 | /// 63 | /// 64 | public override IServiceRegistration Register(Type serviceType, Func implementationFactory, ServiceLifetime lifetime) 65 | { 66 | var builder = _container 67 | .Register(c => implementationFactory(Wrap(c))) 68 | .As(serviceType); 69 | 70 | 71 | if (lifetime == ServiceLifetime.Singleton) 72 | builder.SingleInstance(); 73 | else if (lifetime == ServiceLifetime.Scoped) 74 | builder.InstancePerLifetimeScope(); 75 | 76 | return this; 77 | } 78 | 79 | 80 | private static IServiceProvider Wrap(IComponentContext componentContext) 81 | { 82 | return new AutofacServiceProvider(componentContext); 83 | } 84 | } -------------------------------------------------------------------------------- /src/KickStart.DependencyInjection/DependencyInjectionRegistration.cs: -------------------------------------------------------------------------------- 1 | using KickStart.Services; 2 | 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | using ServiceLifetime = KickStart.Services.ServiceLifetime; 6 | 7 | namespace KickStart.DependencyInjection; 8 | 9 | /// 10 | /// Microsoft.Extensions.DependencyInjection implementation for . 11 | /// 12 | /// 13 | public class DependencyInjectionRegistration : ServiceRegistrationBase 14 | { 15 | private readonly IServiceCollection _container; 16 | 17 | /// 18 | /// Initializes a new instance of the class. 19 | /// 20 | /// The container. 21 | /// The current service . 22 | public DependencyInjectionRegistration(Context serviceContext, IServiceCollection container) : base(serviceContext) 23 | { 24 | _container = container; 25 | } 26 | 27 | 28 | /// 29 | /// Registers a service of the type specified in with an 30 | /// implementation of the type specified in using 31 | /// the specified . 32 | /// 33 | /// The type of the service to register. 34 | /// The implementation type of the service. 35 | /// The service lifetime. 36 | /// 37 | /// A reference to this instance after the operation has completed. 38 | /// 39 | public override IServiceRegistration Register(Type serviceType, Type implementationType, ServiceLifetime lifetime) 40 | { 41 | if (lifetime == ServiceLifetime.Singleton) 42 | _container.AddSingleton(serviceType, implementationType); 43 | else if (lifetime == ServiceLifetime.Scoped) 44 | _container.AddScoped(serviceType, implementationType); 45 | else 46 | _container.AddTransient(serviceType, implementationType); 47 | 48 | return this; 49 | } 50 | 51 | /// 52 | /// Registers a service of the type specified in with a 53 | /// factory specified in using 54 | /// the specified . 55 | /// 56 | /// The type of the service to register. 57 | /// The factory that creates the service. 58 | /// The service lifetime. 59 | /// 60 | /// A reference to this instance after the operation has completed. 61 | /// 62 | /// 63 | public override IServiceRegistration Register(Type serviceType, Func implementationFactory, ServiceLifetime lifetime) 64 | { 65 | if (lifetime == ServiceLifetime.Singleton) 66 | _container.AddSingleton(serviceType, implementationFactory); 67 | else if (lifetime == ServiceLifetime.Scoped) 68 | _container.AddScoped(serviceType, implementationFactory); 69 | else 70 | _container.AddTransient(serviceType, implementationFactory); 71 | 72 | return this; 73 | } 74 | } 75 | --------------------------------------------------------------------------------