Browse Source

Added extension methods to add luticate services

develop
Robin Thoni 6 years ago
parent
commit
9367a6beb6

+ 4
- 32
Luticate2.Auth.ConsoleSample/Program.cs View File

2
 using Luticate2.Auth.Auth.Business;
2
 using Luticate2.Auth.Auth.Business;
3
 using Luticate2.Auth.Auth.DataAccess;
3
 using Luticate2.Auth.Auth.DataAccess;
4
 using Luticate2.Auth.ConsoleSample.Commands;
4
 using Luticate2.Auth.ConsoleSample.Commands;
5
+using Luticate2.Auth.Utils.Business.Converters;
5
 using Microsoft.EntityFrameworkCore;
6
 using Microsoft.EntityFrameworkCore;
6
 using Microsoft.Extensions.DependencyInjection;
7
 using Microsoft.Extensions.DependencyInjection;
7
 using NClap.Metadata;
8
 using NClap.Metadata;
24
     class Program
25
     class Program
25
     {
26
     {
26
         public static IServiceProvider ServiceProvider;
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
         static void Main(string[] args)
29
         static void Main(string[] args)
36
         {
30
         {
37
             IServiceCollection services = new ServiceCollection();
31
             IServiceCollection services = new ServiceCollection();
32
+
33
+            services.AddLuObjectConverterDescriptors();
34
+            services.AddLuObjectConverters();
38
             
35
             
39
             services.AddScoped<LuGroupsBusiness>();
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
             services.AddDbContext<Luticate2DbContext>(options =>
38
             services.AddDbContext<Luticate2DbContext>(options =>
67
             {
39
             {
68
                 options.UseNpgsql(@"Host=localhost;Database=luticate2;Username=dev;Password=dev");
40
                 options.UseNpgsql(@"Host=localhost;Database=luticate2;Username=dev;Password=dev");

+ 1
- 7
Luticate2.Auth.Tests/Business/ExpressionConverter/ExpressionConverterTests.cs View File

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

+ 4
- 37
Luticate2.Auth.Tests/Business/ObjectConverter/ObjectConverterTests.cs View File

1
 using System;
1
 using System;
2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
-using System.Collections.ObjectModel;
4
 using System.Linq;
3
 using System.Linq;
5
 using System.Linq.Expressions;
4
 using System.Linq.Expressions;
6
 using Luticate2.Auth.Utils.Business.Converters;
5
 using Luticate2.Auth.Utils.Business.Converters;
7
 using Luticate2.Auth.Utils.Business.Fields;
6
 using Luticate2.Auth.Utils.Business.Fields;
8
-using Luticate2.Auth.Utils.Business.ObjectConverter;
9
-using Luticate2.Auth.Utils.Business.ObjectConverterDescriptor;
10
 using Luticate2.Auth.Utils.Dbo;
7
 using Luticate2.Auth.Utils.Dbo;
11
 using Luticate2.Auth.Utils.Dbo.Fields;
8
 using Luticate2.Auth.Utils.Dbo.Fields;
12
 using Luticate2.Auth.Utils.Dbo.Result;
9
 using Luticate2.Auth.Utils.Dbo.Result;
20
     {
17
     {
21
         protected IServiceProvider GetServiceProvider()
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
             var services = new ServiceCollection();
20
             var services = new ServiceCollection();
46
-            services.AddSingleton<ILuObjectConverterDescriptorIdentity, LuObjectConverterDescriptorIdentity>();
47
-            services.AddSingleton(typeILuObjectConverterDescriptorEnumerable, typeof(LuObjectConverterDescriptorEnumerable));
21
+            services.AddLuObjectConverterDescriptors();
48
             services.AddSingleton<ILuObjectConverterDescriptor<TestDbo1, TestModel1>, LuOcdTest1>();
22
             services.AddSingleton<ILuObjectConverterDescriptor<TestDbo1, TestModel1>, LuOcdTest1>();
49
             services.AddSingleton<ILuObjectConverterDescriptor<TestDbo2, TestModel2>, LuOcdTest2>();
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
             var serviceProvider = services.BuildServiceProvider();
29
             var serviceProvider = services.BuildServiceProvider();
63
             return serviceProvider;
30
             return serviceProvider;

+ 5
- 0
Luticate2.Auth.Tests/Business/ObjectConverter/Objects.cs View File

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

+ 59
- 0
Luticate2.Auth/Utils/Business/Converters/LuConvertersExtensions.cs View File

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 View File

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

+ 0
- 1
Luticate2.Auth/Utils/Business/ExpressionConverter/LuExpressionParamReplaceVisitor.cs View File

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

Loading…
Cancel
Save