You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 4.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.Collections.Generic;
  3. using Luticate2.Auth.Business.Auth;
  4. using Luticate2.Auth.Business.Auth.DMEC;
  5. using Luticate2.Auth.Business.Auth.PartialObjectCopier;
  6. using Luticate2.Auth.Business.Fields.DMEC;
  7. using Luticate2.Auth.ConsoleSample.Commands;
  8. using Luticate2.Auth.DataAccess;
  9. using Luticate2.Auth.DataAccess.Models;
  10. using Luticate2.Auth.Dbo.Auth;
  11. using Luticate2.Auth.Interfaces;
  12. using Microsoft.EntityFrameworkCore;
  13. using Microsoft.Extensions.DependencyInjection;
  14. using Microsoft.Extensions.DependencyInjection.Extensions;
  15. using NClap.Metadata;
  16. using NClap.Repl;
  17. namespace Luticate2.Auth.ConsoleSample
  18. {
  19. enum CommandsEnum
  20. {
  21. [Command(typeof(ListCommand), Description = "Lists Luticate2 items", LongName = "ls", ShortName = "l")]
  22. ListItems,
  23. [Command(typeof(CreateCommand), Description = "Creates Luticate2 items", LongName = "create", ShortName = "c")]
  24. CreateItems,
  25. [Command(typeof(ExitCommand), Description = "Exits the shell")]
  26. Exit
  27. }
  28. class Program
  29. {
  30. public static IServiceProvider ServiceProvider;
  31. protected static void AddILuExpressionConverter<TTypeFrom, TTypeTo, TTypeImpl>(IServiceCollection services)
  32. where TTypeImpl : class, ILuExpressionConverter<TTypeFrom, TTypeTo>
  33. {
  34. services.AddSingleton<ILuExpressionConverter<TTypeFrom, TTypeTo>, TTypeImpl>();
  35. services.TryAddSingleton<ILuExpressionConverter<TTypeFrom>, TTypeImpl>();
  36. }
  37. static void Main(string[] args)
  38. {
  39. IServiceCollection services = new ServiceCollection();
  40. services.AddScoped<LuGroupsBusiness>();
  41. services.AddSingleton<ILuPartialObjectCopier<LuObjectsMetadata, LuObjectsMetadataDbo>, LuPOCObjectsMetadataToDbo>();
  42. services.AddSingleton<ILuPartialObjectCopier<LuGroups, LuGroupDbo>, LuPOCGroupsToDbo>();
  43. services.AddSingleton<ILuPartialObjectCopier<LuGroupDbo, LuGroups>, LuPOCGroupsToModel>();
  44. // services.AddSingleton<ILuDboModelExpressionConverter<TestDbo1, TestModel1>, LuDMECTest1>();
  45. AddILuExpressionConverter<LuGroupDbo, LuGroups, LuDMECGroupsToModel>(services);
  46. AddILuExpressionConverter<string, string, LuExpressionConverterIdentity<string>>(services);
  47. AddILuExpressionConverter<Guid, Guid, LuExpressionConverterIdentity<Guid>>(services);
  48. AddILuExpressionConverter<bool, bool, LuExpressionConverterIdentity<bool>>(services);
  49. // services.AddSingleton<ILuFieldsExpressions<LuObjectsMetadataDbo, LuObjectsMetadata>, LuFieldsExpressionsLuMetadataDboLuMetadata>();
  50. // services.AddSingleton<ILuFieldsExpressions<LuGroupDbo, LuGroups>, LuFieldsExpressionsLuGroupDboLuGroups>();
  51. //
  52. // services.AddSingleton<ILuFieldsExpressions<string, string>, LuFieldsExpressionsString>();
  53. // services.AddSingleton<ILuFieldsExpressions<int, int>, LuFieldsExpressions<int, int>>();
  54. // services.AddSingleton<ILuFieldsExpressions<Guid, Guid>, LuFieldsExpressions<Guid, Guid>>();
  55. //
  56. // services.AddSingleton<ILuFieldsExpressions<DateTime, DateTime>, LuFieldsExpressions<DateTime, DateTime>>();
  57. // services.AddSingleton<ILuFieldsExpressions<DateTimeOffset, DateTimeOffset>, LuFieldsExpressions<DateTimeOffset, DateTimeOffset>>();
  58. // services.AddSingleton<ILuFieldsExpressions<DateTime, DateTimeOffset>, LuFieldsExpressions<DateTime, DateTimeOffset>>();
  59. // services.AddSingleton<ILuFieldsExpressions<DateTimeOffset, DateTime>, LuFieldsExpressions<DateTimeOffset, DateTime>>();
  60. //
  61. // services.AddSingleton<ILuFieldsExpressions<DateTime?, DateTime?>, LuFieldsExpressions<DateTime?, DateTime?>>();
  62. // services.AddSingleton<ILuFieldsExpressions<DateTimeOffset?, DateTimeOffset?>, LuFieldsExpressions<DateTimeOffset?, DateTimeOffset?>>();
  63. // services.AddSingleton<ILuFieldsExpressions<DateTime?, DateTimeOffset?>, LuFieldsExpressions<DateTime?, DateTimeOffset?>>();
  64. // services.AddSingleton<ILuFieldsExpressions<DateTimeOffset?, DateTime?>, LuFieldsExpressions<DateTimeOffset?, DateTime?>>();
  65. services.AddDbContext<Luticate2DbContext>(options =>
  66. {
  67. options.UseNpgsql(@"Host=localhost;Database=luticate2;Username=dev;Password=dev");
  68. options.UseInternalServiceProvider(new ServiceCollection()
  69. .AddEntityFrameworkNpgsql()
  70. .BuildServiceProvider());
  71. }, ServiceLifetime.Transient);
  72. ServiceProvider = services.BuildServiceProvider();
  73. var loop = new Loop(typeof(CommandsEnum));
  74. loop.Execute();
  75. }
  76. }
  77. }