protected override void Load(ContainerBuilder builder) { base.Load(builder); // Autofac & AdaptiveClient List <IEndPointConfiguration> endPoints = EndPointUtilities.LoadEndPoints(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "appsettings.json")).ToList(); IEndPointConfiguration backOffice = endPoints.FirstOrDefault(x => x.API_Name == API_Name.BackOffice && x.ProviderName == DataBaseProviderName.MySQL); IEndPointConfiguration frontOffice = endPoints.FirstOrDefault(x => x.API_Name == API_Name.StoreFront && x.ProviderName == DataBaseProviderName.MySQL); if (backOffice != null) { backOffice.ConnectionString = ConnectionstringUtility.BuildConnectionString(backOffice.ConnectionString); } if (frontOffice != null) { frontOffice.ConnectionString = ConnectionstringUtility.BuildConnectionString(frontOffice.ConnectionString); } builder.RegisterModule(new LeaderAnalytics.AdaptiveClient.EntityFrameworkCore.AutofacModule()); builder.RegisterInstance(endPoints).SingleInstance(); RegistrationHelper registrationHelper = new RegistrationHelper(builder); registrationHelper .RegisterEndPoints(endPoints) .RegisterModule(new Zamagon.Services.Common.AdaptiveClientModule()) .RegisterModule(new Zamagon.Services.BackOffice.AdaptiveClientModule()) .RegisterModule(new Zamagon.Services.StoreFront.AdaptiveClientModule()); }
public void Setup() { LogMessages = new List <string>(); builder = new ContainerBuilder(); EndPoints = EndPointUtilities.LoadEndPoints("EndPoints.json").ToList(); registrationHelper = new RegistrationHelper(builder); builder.RegisterModule(new AutofacModule()); registrationHelper.RegisterModule(new AdaptiveClientModule(EndPoints, msg => this.LogMessages.Add(msg))); }
public App() { // Register SyncfusionLicense // Check to see if API KEY is in your Environment Variables //if (Environment.GetEnvironmentVariable("SYNCFUSION_API_KEY") == null) //{ // // If key is not available, use free community license here: https://www.syncfusion.com/products/communitylicense // Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MTMwNjE1QDMxMzcyZTMyMmUzMEFlSlpZMDNRQVFhUy9pOHQ4dzlObVNNbGNsQ3I2bE15NE50U2dzQ1lYK1k9"); //} //else //{ // Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense( // Environment.GetEnvironmentVariable("SYNCFUSION_API_KEY")); //} // Added because was still prompting users from the store Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MTMwNjE1QDMxMzcyZTMyMmUzMEFlSlpZMDNRQVFhUy9pOHQ4dzlObVNNbGNsQ3I2bE15NE50U2dzQ1lYK1k9"); this.InitializeComponent(); this.Suspending += OnSuspending; // build the Autofac container IEnumerable <IEndPointConfiguration> endPoints = EndPointUtilities.LoadEndPoints("EndPoints.json"); string fileRoot = Windows.Storage.ApplicationData.Current.LocalFolder.Path; // Commented out because I'm currently not running MySQL // KanbanTasker.Services.ConnectionstringUtility.PopulateConnectionStrings(fileRoot, endPoints); ContainerBuilder builder = new ContainerBuilder(); builder.RegisterModule(new LeaderAnalytics.AdaptiveClient.EntityFrameworkCore.AutofacModule()); builder.RegisterModule(new AutofacModule()); builder.RegisterModule(new Services.AutofacModule()); RegistrationHelper registrationHelper = new RegistrationHelper(builder); registrationHelper .RegisterEndPoints(endPoints) .RegisterModule(new KanbanTasker.Services.AdaptiveClientModule()); container = builder.Build(); IDatabaseUtilities databaseUtilities = container.Resolve <IDatabaseUtilities>(); // Create all databases or apply migrations foreach (IEndPointConfiguration ep in endPoints.Where(x => x.EndPointType == EndPointType.DBMS)) { Task.Run(() => databaseUtilities.CreateOrUpdateDatabase(ep)).Wait(); } AppCenter.Start("a57ee001-5ab0-46f5-aa5a-4d1b84cd6b66", typeof(Analytics), typeof(Crashes)); }
public Db_MySQL CreateDbContext(string[] args) { string fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "EndPoints.json"); string connectionString = EndPointUtilities.LoadEndPoints(fileName, false).First(x => x.API_Name == API_Name.Kanban && x.ProviderName == DatabaseProvider.MySQL).ConnectionString; DbContextOptionsBuilder dbOptions = new DbContextOptionsBuilder(); dbOptions.UseMySql(connectionString); Db_MySQL db = new Db_MySQL(dbOptions.Options); return(db); }
public static void RegisterComponents(ContainerBuilder builder) { RegistrationHelper registrationHelper = new RegistrationHelper(builder); // Register endPoints before registering clients registrationHelper.RegisterEndPoints(EndPointUtilities.LoadEndPoints("appsettings.json")); // Register services registrationHelper.RegisterService<UsersService_WebAPI, IUsersService>(EndPointType.HTTP, API_Name.UsersAPI, DataProvider.WebAPI); registrationHelper.RegisterService<UsersService_MSSQL, IUsersService>(EndPointType.InProcess, API_Name.UsersAPI, DataProvider.MSSQL); registrationHelper.RegisterService<UsersService_MySQL, IUsersService>(EndPointType.InProcess, API_Name.UsersAPI, DataProvider.MySQL); // Register logger (optional) registrationHelper.RegisterLogger(logMessage => Console.WriteLine(logMessage.Substring(0, 203))); builder.RegisterType<Demo>(); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); var formatterSettings = JsonSerializerSettingsProvider.CreateSerializerSettings(); formatterSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; formatterSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); JsonOutputFormatter formatter = new JsonOutputFormatter(formatterSettings, System.Buffers.ArrayPool <char> .Shared); services.Configure <MvcOptions>(options => { options.OutputFormatters.RemoveType <JsonOutputFormatter>(); options.OutputFormatters.Insert(0, formatter); }); // Autofac & AdaptiveClient string fileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "EndPoints.json"); IEnumerable <IEndPointConfiguration> endPoints = EndPointUtilities.LoadEndPoints(fileName); string fileRoot = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); KanbanTasker.Services.ConnectionstringUtility.PopulateConnectionStrings(fileRoot, endPoints); ContainerBuilder builder = new ContainerBuilder(); builder.Populate(services); builder.RegisterModule(new LeaderAnalytics.AdaptiveClient.EntityFrameworkCore.AutofacModule()); builder.RegisterModule(new Services.AutofacModule()); RegistrationHelper registrationHelper = new RegistrationHelper(builder); registrationHelper .RegisterEndPoints(endPoints) .RegisterModule(new KanbanTasker.Services.AdaptiveClientModule()); var container = builder.Build(); IDatabaseUtilities databaseUtilities = container.Resolve <IDatabaseUtilities>(); // Create all databases or apply migrations foreach (IEndPointConfiguration ep in endPoints.Where(x => x.EndPointType == EndPointType.DBMS)) { Task.Run(() => databaseUtilities.CreateOrUpdateDatabase(ep)).Wait(); } return(container.Resolve <IServiceProvider>()); }
protected async Task CreateTestArtifacts() { EndPoints = EndPointUtilities.LoadEndPoints("appsettings.json"); if (EndPoints.Any(x => x.ProviderName == DataBaseProviderName.MySQL)) { EndPoints.First(x => x.API_Name == API_Name.BackOffice && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString = ConnectionstringUtility.BuildConnectionString(EndPoints.First(x => x.API_Name == API_Name.BackOffice && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString); EndPoints.First(x => x.API_Name == API_Name.StoreFront && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString = ConnectionstringUtility.BuildConnectionString(EndPoints.First(x => x.API_Name == API_Name.StoreFront && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString); } Builder = new ContainerBuilder(); Builder.RegisterModule(new AutofacModule()); Builder.RegisterModule(new LeaderAnalytics.AdaptiveClient.EntityFrameworkCore.AutofacModule()); RegistrationHelper registrationHelper = new RegistrationHelper(Builder); registrationHelper.RegisterModule(new AdaptiveClientModule()); Container = Builder.Build(); BOServiceClient = Container.Resolve <IAdaptiveClient <IBOServiceManifest> >(); }
public static IEnumerable <IEndPointConfiguration> ReadEndPointsFromDisk() { List <IEndPointConfiguration> endPoints = EndPointUtilities.LoadEndPoints(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "appsettings.json")).ToList(); IEndPointConfiguration backOffice = endPoints.FirstOrDefault(x => x.API_Name == API_Name.BackOffice && x.ProviderName == DataBaseProviderName.MySQL); IEndPointConfiguration frontOffice = endPoints.FirstOrDefault(x => x.API_Name == API_Name.StoreFront && x.ProviderName == DataBaseProviderName.MySQL); if (backOffice != null) { backOffice.ConnectionString = ConnectionstringUtility.BuildConnectionString(endPoints.First(x => x.API_Name == API_Name.BackOffice && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString); } if (frontOffice != null) { frontOffice.ConnectionString = ConnectionstringUtility.BuildConnectionString(endPoints.First(x => x.API_Name == API_Name.StoreFront && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString); } return(endPoints); }
static void Main(string[] args) { List <IEndPointConfiguration> endPoints = EndPointUtilities.LoadEndPoints("appsettings.json").ToList(); ContainerBuilder builder = new ContainerBuilder(); AutofacModule.RegisterComponents(builder); IContainer container = builder.Build(); Console.Clear(); DisplayIntro(); int i = 0; endPoints.ForEach(ep => Console.WriteLine($"{i++}. {ep.Name}")); Console.WriteLine(); while (true) { int cursorRow = 13; SetCursorToRow(cursorRow++); Console.Write("Choose an EndPoint (connection string) from the list or enter Q to exit:"); ConsoleKeyInfo lastKey = Console.ReadKey(); if (lastKey.Key == ConsoleKey.Q) { break; } bool isParsed = int.TryParse(lastKey.KeyChar.ToString(), out int index); if (!isParsed || index >= endPoints.Count) { continue; } SetCursorToRow(cursorRow++); IEndPointConfiguration ep = endPoints[index]; Demo demo = container.Resolve <Demo>(); demo.DisplayUserName(ep); } Console.WriteLine("Adaptive Client demo ended."); }
protected override void Load(ContainerBuilder builder) { RegistrationHelper registrationHelper = new RegistrationHelper(builder); List <IEndPointConfiguration> endPoints = EndPointUtilities.LoadEndPoints("appsettings.json").ToList(); builder.RegisterInstance(endPoints).SingleInstance(); // Register the endpoints with Autofac. Most applications will not need to do this. // API Name is an arbitrary name of your choosing that AdaptiveClient uses to link interfaces (IUsersService) to the // EndPoints that expose them (Prod_SQL_01, Prod_WebAPI_01). The API_Name used here must match the API_Name // of related EndPoints in EndPoints.json file. // Register the endpoints with AdaptiveClient. All applications using AdaptiveClient need to do this. Always register endPoints before registering clients. registrationHelper.RegisterEndPoints(endPoints); registrationHelper.RegisterService <UsersService_WebAPI, IUsersService>(EndPointType.HTTP, API_Name.DemoAPI, DataProvider.HTTP); registrationHelper.RegisterService <UsersService_MSSQL, IUsersService>(EndPointType.InProcess, API_Name.DemoAPI, DataProvider.MSSQL); registrationHelper.RegisterService <UsersService_MySQL, IUsersService>(EndPointType.InProcess, API_Name.DemoAPI, DataProvider.MySQL); registrationHelper.RegisterLogger(logMessage => Logger.Message = logMessage); // EndPoint Validators // No servers for MSSQL or MySQL and we don't have an API url so register some mocks... Mock <IEndPointValidator> validatorMock = new Mock <IEndPointValidator>(); validatorMock.Setup(x => x.IsInterfaceAlive(It.IsAny <IEndPointConfiguration>())).Returns(true); builder.RegisterInstance(validatorMock.Object).Keyed <IEndPointValidator>(EndPointType.InProcess + DataProvider.MSSQL); builder.RegisterInstance(validatorMock.Object).Keyed <IEndPointValidator>(EndPointType.InProcess + DataProvider.MySQL); builder.RegisterInstance(validatorMock.Object).Keyed <IEndPointValidator>(EndPointType.HTTP + DataProvider.HTTP); // In a real app... //registrationHelper.RegisterEndPointValidator<MSSQL_EndPointValidator>(EndPointType.InProcess, DataProvider.MSSQL); //registrationHelper.RegisterEndPointValidator<MySQL_EndPointValidator>(EndPointType.InProcess, DataProvider.MySQL); // WCF (will fail and fall back) var usersServiceMock = new Mock <IUsersService>(); usersServiceMock.Setup(x => x.SaveUser(It.IsAny <User>())).Throws(new Exception("Cant find database server.")); usersServiceMock.Setup(x => x.GetUserByID(It.IsAny <int>())).Throws(new Exception("Cant find database server.")); builder.RegisterInstance(usersServiceMock.Object).Keyed <IUsersService>(EndPointType.WCF + DataProvider.HTTP); registrationHelper.RegisterLogger(logMessage => Logger.Message = logMessage); }
public static string GetConnectionString(string filePath, string apiName, string providerName) { IEnumerable <IEndPointConfiguration> endPoints = EndPointUtilities.LoadEndPoints(filePath, false); return(endPoints.First(x => x.API_Name == apiName && x.ProviderName == providerName).ConnectionString); }
public void Register(RegistrationHelper registrationHelper) { IEnumerable <IEndPointConfiguration> endPoints = EndPointUtilities.LoadEndPoints("appsettings.json"); if (endPoints.Any(x => x.ProviderName == DataBaseProviderName.MySQL)) { endPoints.First(x => x.API_Name == API_Name.BackOffice && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString = ConnectionstringUtility.BuildConnectionString(endPoints.First(x => x.API_Name == API_Name.BackOffice && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString); endPoints.First(x => x.API_Name == API_Name.StoreFront && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString = ConnectionstringUtility.BuildConnectionString(endPoints.First(x => x.API_Name == API_Name.StoreFront && x.ProviderName == DataBaseProviderName.MySQL).ConnectionString); } registrationHelper // EndPoints (Endpoints must be registered FIRST) .RegisterEndPoints(endPoints) // -- EndPoint Validator .RegisterEndPointValidator <MSSQL_EndPointValidator>(EndPointType.DBMS, DataBaseProviderName.MSSQL) .RegisterEndPointValidator <MySQL_EndPointValidator>(EndPointType.DBMS, DataBaseProviderName.MySQL) // --- BackOffice Services --- // MSSQL .RegisterService <Artifacts.BackOffice.MSSQL.AccountsService, IAccountsService>(EndPointType.DBMS, API_Name.BackOffice, DataBaseProviderName.MSSQL) .RegisterService <Artifacts.BackOffice.MSSQL.PaymentsService, IPaymentsService>(EndPointType.DBMS, API_Name.BackOffice, DataBaseProviderName.MSSQL) // MySQL .RegisterService <Artifacts.BackOffice.MySQL.AccountsService, IAccountsService>(EndPointType.DBMS, API_Name.BackOffice, DataBaseProviderName.MySQL) .RegisterService <Artifacts.BackOffice.MySQL.PaymentsService, IPaymentsService>(EndPointType.DBMS, API_Name.BackOffice, DataBaseProviderName.MySQL) // --- StoreFront Services --- // MSSQL .RegisterService <Artifacts.StoreFront.MSSQL.OrdersService, IOrdersService>(EndPointType.DBMS, API_Name.StoreFront, DataBaseProviderName.MSSQL) .RegisterService <Artifacts.StoreFront.MSSQL.ProductsService, IProductsService>(EndPointType.DBMS, API_Name.StoreFront, DataBaseProviderName.MSSQL) // MySQL .RegisterService <Artifacts.StoreFront.MySQL.OrdersService, IOrdersService>(EndPointType.DBMS, API_Name.StoreFront, DataBaseProviderName.MySQL) .RegisterService <Artifacts.StoreFront.MySQL.ProductsService, IProductsService>(EndPointType.DBMS, API_Name.StoreFront, DataBaseProviderName.MySQL) // DbContexts .RegisterDbContext <Artifacts.BackOffice.Db>(API_Name.BackOffice) .RegisterDbContext <Artifacts.StoreFront.Db>(API_Name.StoreFront) // DbContextOptions .RegisterDbContextOptions <DbContextOptions_MSSQL>(DataBaseProviderName.MSSQL) .RegisterDbContextOptions <DbContextOptions_MySQL>(DataBaseProviderName.MySQL) // Migration Contexts .RegisterMigrationContext <Artifacts.BackOffice.Db_MSSQL>(API_Name.BackOffice, DataBaseProviderName.MSSQL) .RegisterMigrationContext <Artifacts.BackOffice.Db_MySQL>(API_Name.BackOffice, DataBaseProviderName.MySQL) .RegisterMigrationContext <Artifacts.StoreFront.Db_MSSQL>(API_Name.StoreFront, DataBaseProviderName.MSSQL) .RegisterMigrationContext <Artifacts.StoreFront.Db_MySQL>(API_Name.StoreFront, DataBaseProviderName.MySQL) // Database Initializers .RegisterDatabaseInitializer <BODatabaseInitializer>(API_Name.BackOffice, DataBaseProviderName.MSSQL) .RegisterDatabaseInitializer <BODatabaseInitializer>(API_Name.BackOffice, DataBaseProviderName.MySQL) // register same class for both providers. If we had stored procs, etc. that were different we could just create a new class. .RegisterDatabaseInitializer <SFDatabaseInitializer>(API_Name.StoreFront, DataBaseProviderName.MSSQL) .RegisterDatabaseInitializer <SFDatabaseInitializer>(API_Name.StoreFront, DataBaseProviderName.MySQL) // Service Manifests .RegisterServiceManifest <Artifacts.BackOffice.BOServiceManifest, IBOServiceManifest>(EndPointType.DBMS, API_Name.BackOffice, DataBaseProviderName.MSSQL) .RegisterServiceManifest <Artifacts.BackOffice.BOServiceManifest, IBOServiceManifest>(EndPointType.DBMS, API_Name.BackOffice, DataBaseProviderName.MySQL) .RegisterServiceManifest <Artifacts.StoreFront.SFServiceManifest, ISFServiceManifest>(EndPointType.DBMS, API_Name.StoreFront, DataBaseProviderName.MSSQL); }