Bladeren bron

Added extension methods to add luticate services

develop
Robin Thoni 6 jaren geleden
bovenliggende
commit
9367a6beb6

+ 4
- 32
Luticate2.Auth.ConsoleSample/Program.cs Bestand weergeven

@@ -2,6 +2,7 @@
2 2
 using Luticate2.Auth.Auth.Business;
3 3
 using Luticate2.Auth.Auth.DataAccess;
4 4
 using Luticate2.Auth.ConsoleSample.Commands;
5
+using Luticate2.Auth.Utils.Business.Converters;
5 6
 using Microsoft.EntityFrameworkCore;
6 7
 using Microsoft.Extensions.DependencyInjection;
7 8
 using NClap.Metadata;
@@ -24,45 +25,16 @@ namespace Luticate2.Auth.ConsoleSample
24 25
     class Program
25 26
     {
26 27
         public static IServiceProvider ServiceProvider;
27
-
28
-//        protected static void AddILuExpressionConverter<TTypeFrom, TTypeTo, TTypeImpl>(IServiceCollection services)
29
-//            where TTypeImpl : class, ILuExpressionConverter<TTypeFrom, TTypeTo>
30
-//        {
31
-//            services.AddSingleton<ILuExpressionConverter<TTypeFrom, TTypeTo>, TTypeImpl>();
32
-//            services.TryAddSingleton<ILuExpressionConverter<TTypeFrom>, TTypeImpl>();
33
-//        }
34 28
         
35 29
         static void Main(string[] args)
36 30
         {
37 31
             IServiceCollection services = new ServiceCollection();
32
+
33
+            services.AddLuObjectConverterDescriptors();
34
+            services.AddLuObjectConverters();
38 35
             
39 36
             services.AddScoped<LuGroupsBusiness>();
40 37
 
41
-
42
-//            services.AddSingleton<ILuDboModelExpressionConverter<TestDbo1, TestModel1>, LuDMECTest1>();
43
-//            AddILuExpressionConverter<LuGroupDbo, LuGroups, LuDMECGroupsToModel>(services);
44
-//            AddILuExpressionConverter<string, string, LuExpressionConverterIdentity<string>>(services);
45
-//            AddILuExpressionConverter<Guid, Guid, LuExpressionConverterIdentity<Guid>>(services);
46
-//            AddILuExpressionConverter<bool, bool, LuExpressionConverterIdentity<bool>>(services);
47
-
48
-
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
-
66 38
             services.AddDbContext<Luticate2DbContext>(options =>
67 39
             {
68 40
                 options.UseNpgsql(@"Host=localhost;Database=luticate2;Username=dev;Password=dev");

+ 1
- 7
Luticate2.Auth.Tests/Business/ExpressionConverter/ExpressionConverterTests.cs Bestand weergeven

@@ -4,7 +4,6 @@ using System.Linq;
4 4
 using System.Linq.Expressions;
5 5
 using Luticate2.Auth.Utils.Business.Converters;
6 6
 using Luticate2.Auth.Utils.Business.ExpressionConverter;
7
-using Luticate2.Auth.Utils.Business.ObjectConverterDescriptor;
8 7
 using Luticate2.Auth.Utils.Interfaces;
9 8
 using Microsoft.Extensions.DependencyInjection;
10 9
 using Xunit;
@@ -16,13 +15,8 @@ namespace Luticate2.Auth.Tests.Business.ExpressionConverter
16 15
 
17 16
         protected IServiceProvider GetServiceProvider()
18 17
         {
19
-            var typeILuObjectConverterDescriptor = typeof(ILuObjectConverterDescriptor<,>);
20
-            var typeILuObjectConverterDescriptorEnumerable =
21
-                typeILuObjectConverterDescriptor.MakeGenericType(typeof(Enumerable), typeof(Enumerable));
22
-
23 18
             var services = new ServiceCollection();
24
-            services.AddSingleton<ILuObjectConverterDescriptorIdentity, LuObjectConverterDescriptorIdentity>();
25
-            services.AddSingleton(typeILuObjectConverterDescriptorEnumerable, typeof(LuObjectConverterDescriptorEnumerable));
19
+            services.AddLuObjectConverterDescriptors();
26 20
             services.AddSingleton<ILuObjectConverterDescriptor<TestDbo1, TestModel1>, LuOcdTest1>();
27 21
             services.AddSingleton<ILuObjectConverterDescriptor<TestDbo2, TestModel2>, LuOcdTest2>();
28 22
 

+ 4
- 37
Luticate2.Auth.Tests/Business/ObjectConverter/ObjectConverterTests.cs Bestand weergeven

@@ -1,12 +1,9 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
-using System.Collections.ObjectModel;
4 3
 using System.Linq;
5 4
 using System.Linq.Expressions;
6 5
 using Luticate2.Auth.Utils.Business.Converters;
7 6
 using Luticate2.Auth.Utils.Business.Fields;
8
-using Luticate2.Auth.Utils.Business.ObjectConverter;
9
-using Luticate2.Auth.Utils.Business.ObjectConverterDescriptor;
10 7
 using Luticate2.Auth.Utils.Dbo;
11 8
 using Luticate2.Auth.Utils.Dbo.Fields;
12 9
 using Luticate2.Auth.Utils.Dbo.Result;
@@ -20,44 +17,14 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
20 17
     {
21 18
         protected IServiceProvider GetServiceProvider()
22 19
         {
23
-            var typeILuObjectConverterDescriptor = typeof(ILuObjectConverterDescriptor<,>);
24
-            var typeILuObjectConverterDescriptorEnumerable =
25
-                typeILuObjectConverterDescriptor.MakeGenericType(typeof(Enumerable), typeof(Enumerable));
26
-
27
-            var typeILuObjectConverter = typeof(ILuObjectConverter<,>);
28
-            var listTypes = new []
29
-            {
30
-                typeof(IEnumerable<>),
31
-                typeof(ICollection<>),
32
-                typeof(Collection<>),
33
-                typeof(IList<>),
34
-                typeof(List<>)
35
-            };
36
-            var listImplemType = new Dictionary<Type, Type>
37
-            {
38
-                {typeof(IEnumerable<>), typeof(LuObjectConverterList)},
39
-                {typeof(ICollection<>), typeof(LuObjectConverterCollection)},
40
-                {typeof(Collection<>), typeof(LuObjectConverterCollection)},
41
-                {typeof(IList<>), typeof(LuObjectConverterList)},
42
-                {typeof(List<>), typeof(LuObjectConverterList)}
43
-            };
44
-
45 20
             var services = new ServiceCollection();
46
-            services.AddSingleton<ILuObjectConverterDescriptorIdentity, LuObjectConverterDescriptorIdentity>();
47
-            services.AddSingleton(typeILuObjectConverterDescriptorEnumerable, typeof(LuObjectConverterDescriptorEnumerable));
21
+            services.AddLuObjectConverterDescriptors();
48 22
             services.AddSingleton<ILuObjectConverterDescriptor<TestDbo1, TestModel1>, LuOcdTest1>();
49 23
             services.AddSingleton<ILuObjectConverterDescriptor<TestDbo2, TestModel2>, LuOcdTest2>();
50 24
 
51
-            services.AddSingleton<ILuObjectConverterIdentity, LuObjectConverterIdentity>();
52
-            foreach (var typeFrom in listTypes)
53
-            {
54
-                foreach (var typeTo in listTypes)
55
-                {
56
-                    services.AddSingleton(typeILuObjectConverter.MakeGenericType(typeFrom, typeTo), listImplemType[typeTo]);
57
-                }
58
-            }
59
-            services.AddSingleton<ILuObjectConverter<TestModel1, TestDbo1>, LuObjectConverterPoco<TestModel1, TestDbo1>>();
60
-            services.AddSingleton<ILuObjectConverter<TestModel2, TestDbo2>, LuObjectConverterPoco<TestModel2, TestDbo2>>();
25
+            services.AddLuObjectConverters();
26
+            services.AddLuObjectConverterPoco<TestModel1, TestDbo1>();
27
+            services.AddLuObjectConverterPoco<TestModel2, TestDbo2>();
61 28
 
62 29
             var serviceProvider = services.BuildServiceProvider();
63 30
             return serviceProvider;

+ 5
- 0
Luticate2.Auth.Tests/Business/ObjectConverter/Objects.cs Bestand weergeven

@@ -39,6 +39,8 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
39 39
         public TestDbo2 Parent { get; set; }
40 40
 
41 41
         public TestDbo1 Unused { get; set; }
42
+
43
+        public int? OptionalInt { get; set; }
42 44
     }
43 45
 
44 46
     public class TestModel1
@@ -61,6 +63,8 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
61 63
         public TestModel1 test_model1 { get; set; }
62 64
 
63 65
         public TestModel2 parent { get; set; }
66
+
67
+        public int? optional_int { get; set; }
64 68
     }
65 69
 
66 70
     public class LuOcdTest1 : LuObjectConverterDescriptor<TestDbo1, TestModel1>
@@ -86,6 +90,7 @@ namespace Luticate2.Auth.Tests.Business.ObjectConverter
86 90
             AddStaticMemberConverter(x => x.NameVirtual, y => y.name + " " + y.name);
87 91
             AddStaticMemberConverter(x => x.TestDbo1, y => y.test_model1);
88 92
             AddStaticMemberConverter(x => x.Parent, y => y.parent);
93
+            AddStaticMemberConverter(x => x.OptionalInt, y => y.optional_int);
89 94
             AddNullMemberConverter<TestDbo1>(x => x.Unused);
90 95
         }
91 96
     }

+ 59
- 0
Luticate2.Auth/Utils/Business/Converters/LuConvertersExtensions.cs Bestand weergeven

@@ -0,0 +1,59 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Collections.ObjectModel;
4
+using System.Linq;
5
+using Luticate2.Auth.Utils.Business.ObjectConverter;
6
+using Luticate2.Auth.Utils.Business.ObjectConverterDescriptor;
7
+using Luticate2.Auth.Utils.Interfaces;
8
+using Microsoft.Extensions.DependencyInjection;
9
+
10
+namespace Luticate2.Auth.Utils.Business.Converters
11
+{
12
+    public static class LuConvertersExtensions
13
+    {
14
+        public static void AddLuObjectConverterDescriptors(this IServiceCollection services)
15
+        {
16
+            var typeILuObjectConverterDescriptor = typeof(ILuObjectConverterDescriptor<,>);
17
+            var typeILuObjectConverterDescriptorEnumerable =
18
+                typeILuObjectConverterDescriptor.MakeGenericType(typeof(Enumerable), typeof(Enumerable));
19
+
20
+            services.AddSingleton<ILuObjectConverterDescriptorIdentity, LuObjectConverterDescriptorIdentity>();
21
+            services.AddSingleton(typeILuObjectConverterDescriptorEnumerable, typeof(LuObjectConverterDescriptorEnumerable));
22
+        }
23
+
24
+        public static void AddLuObjectConverters(this IServiceCollection services)
25
+        {
26
+            var typeILuObjectConverter = typeof(ILuObjectConverter<,>);
27
+            var listTypes = new []
28
+            {
29
+                typeof(IEnumerable<>),
30
+                typeof(ICollection<>),
31
+                typeof(Collection<>),
32
+                typeof(IList<>),
33
+                typeof(List<>)
34
+            };
35
+            var listImplemType = new Dictionary<Type, Type>
36
+            {
37
+                {typeof(IEnumerable<>), typeof(LuObjectConverterList)},
38
+                {typeof(ICollection<>), typeof(LuObjectConverterCollection)},
39
+                {typeof(Collection<>), typeof(LuObjectConverterCollection)},
40
+                {typeof(IList<>), typeof(LuObjectConverterList)},
41
+                {typeof(List<>), typeof(LuObjectConverterList)}
42
+            };
43
+
44
+            services.AddSingleton<ILuObjectConverterIdentity, LuObjectConverterIdentity>();
45
+            foreach (var typeFrom in listTypes)
46
+            {
47
+                foreach (var typeTo in listTypes)
48
+                {
49
+                    services.AddSingleton(typeILuObjectConverter.MakeGenericType(typeFrom, typeTo), listImplemType[typeTo]);
50
+                }
51
+            }
52
+        }
53
+
54
+        public static void AddLuObjectConverterPoco<TTypeFrom, TTypeTo>(this IServiceCollection services)
55
+        {
56
+            services.AddSingleton<ILuObjectConverter<TTypeFrom, TTypeTo>, LuObjectConverterPoco<TTypeFrom, TTypeTo>>();
57
+        }
58
+    }
59
+}

+ 0
- 1
Luticate2.Auth/Utils/Business/ExpressionConverter/LuExpressionConverterVisitor.cs Bestand weergeven

@@ -2,7 +2,6 @@
2 2
 using System.Collections.Generic;
3 3
 using System.Linq;
4 4
 using System.Linq.Expressions;
5
-using Luticate2.Auth.Utils.Business.Converters;
6 5
 using Luticate2.Auth.Utils.Dbo;
7 6
 using Luticate2.Auth.Utils.Dbo.Result;
8 7
 using Luticate2.Auth.Utils.Exceptions;

+ 0
- 1
Luticate2.Auth/Utils/Business/ExpressionConverter/LuExpressionParamReplaceVisitor.cs Bestand weergeven

@@ -1,6 +1,5 @@
1 1
 using System.Collections.Generic;
2 2
 using System.Linq.Expressions;
3
-using Luticate2.Auth.Utils.Business.Converters;
4 3
 using Luticate2.Auth.Utils.Dbo;
5 4
 using Luticate2.Auth.Utils.Dbo.Result;
6 5
 using Luticate2.Auth.Utils.Exceptions;

Laden…
Annuleren
Opslaan