Skip to content

Commit 77c684d

Browse files
committed
Xml experience!
1 parent f8739ad commit 77c684d

6 files changed

Lines changed: 31 additions & 38 deletions

File tree

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
using MongoDB.Bson;
2-
using MongoDB.Bson.Serialization.Attributes;
3-
using SharpRepository.MongoDbRepository;
4-
using SharpRepository.Repository;
1+
using SharpRepository.Repository;
52
using System;
63
using System.Collections.Generic;
74
using System.ComponentModel.DataAnnotations;
85
using System.Linq;
96
using System.Threading.Tasks;
7+
using System.Xml.Serialization;
108

119
namespace SharpRepository.CoreMvc.Models
1210
{
13-
[MongoDbCollectionName("Contacts")]
1411
public class Contact
1512
{
16-
[BsonId] // Needed for MongoDB
17-
[BsonRepresentation(BsonType.ObjectId)] // Needed for MongoDB
1813
[RepositoryPrimaryKey] //Autogenrates value for strings
1914
[Key] //Ef primary key
2015
public string Id { get; set; }
2116
public string Name { get; set; }
2217

2318
[UIHint("_Emails")]
24-
public virtual ICollection<Email> Emails { get; set; }
19+
public virtual List<Email> Emails { get; set; }
2520
}
2621
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System.ComponentModel.DataAnnotations.Schema;
2+
using System.Xml.Serialization;
23

34
namespace SharpRepository.CoreMvc.Models
45
{
56
public class Email
67
{
78
public int Id { get; set; }
89
public string EmailAddress { get; set; }
10+
[XmlIgnore]
911
public Contact Contact;
1012
}
1113
}

SharpRepository.Samples.CoreMvc/SharpRepository.Samples.CoreMvc.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<ProjectReference Include="..\SharpRepository.InMemoryRepository\SharpRepository.InMemoryRepository.csproj" />
18-
<ProjectReference Include="..\SharpRepository.MongoDbRepository\SharpRepository.MongoDbRepository.csproj" />
19-
<ProjectReference Include="..\SharpRepository.EfCoreRepository\SharpRepository.EfCoreRepository.csproj" />
17+
<ProjectReference Include="..\SharpRepository.XmlRepository\SharpRepository.XmlRepository.csproj" />
2018
<ProjectReference Include="..\SharpRepository.Ioc.Microsoft.DependencyInjection\SharpRepository.Ioc.Microsoft.DependencyInjection.csproj" />
2119
</ItemGroup>
2220

21+
<ItemGroup>
22+
<Folder Include="xmlDestinationDirectory\" />
23+
</ItemGroup>
24+
2325
</Project>

SharpRepository.Samples.CoreMvc/Startup.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using SharpRepository.Repository;
88
using SharpRepository.Samples.CoreMvc.CustomRepositories;
99
using System;
10-
using MongoDB.Bson.Serialization;
1110
using SharpRepository.CoreMvc.Models;
1211
using SharpRepository.Samples.CoreMvc;
1312

@@ -31,17 +30,17 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
3130

3231
// services.AddTransient<DbContext, ContactContext>(); // needed if you don't write dbContextClass on json configuration
3332

34-
services.AddTransient<EmailRepository>(r => new EmailRepository(RepositoryFactory.BuildSharpRepositoryConfiguation(Configuration.GetSection("sharpRepository")), "efCore"));
33+
services.AddTransient<EmailRepository>(r => new EmailRepository(RepositoryFactory.BuildSharpRepositoryConfiguation(Configuration.GetSection("sharpRepository")), "xml"));
3534

3635
services.AddTransient<IUserService, UserService>();
3736
services.AddTransient<IUserServiceCustom, UserServiceCustom>();
3837
services.AddTransient<UserRepository>(
3938
r => new UserRepository(
40-
RepositoryFactory.BuildSharpRepositoryConfiguation(Configuration.GetSection("sharpRepository")), "efCore"
39+
RepositoryFactory.BuildSharpRepositoryConfiguation(Configuration.GetSection("sharpRepository")), "xml"
4140
));
4241
// return services.UseSharpRepository(Configuration.GetSection("sharpRepository")); //default InMemory
4342
// return services.UseSharpRepository(Configuration.GetSection("sharpRepository"), "mongoDb"); // for Mongo Db
44-
return services.UseSharpRepository(Configuration.GetSection("sharpRepository"), "efCore"); // for Ef Core
43+
return services.UseSharpRepository(Configuration.GetSection("sharpRepository"), "xml"); // for Ef Core
4544
}
4645

4746
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

SharpRepository.Samples.CoreMvc/appsettings.json

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,11 @@
1010
},
1111
"sharpRepository": {
1212
"repositories": {
13-
"default": "inMemory",
14-
"inMemory": {
15-
"factory": "SharpRepository.InMemoryRepository.InMemoryConfigRepositoryFactory, SharpRepository.InMemoryRepository"
16-
},
17-
"inMemoryNoCaching": {
18-
"factory": "SharpRepository.InMemoryRepository.InMemoryConfigRepositoryFactory, SharpRepository.InMemoryRepository",
19-
"cachingStrategy": "none",
20-
"cachingProvider": "noCachingProvider"
21-
},
22-
"mongoDb": {
23-
"factory": "SharpRepository.MongoDbRepository.MongoDbConfigRepositoryFactory, SharpRepository.MongoDbRepository",
24-
"cachingStrategy": "none",
25-
"cachingProvider": "noCachingProvider",
26-
"connectionString": "mongodb://127.0.0.1/SharpRepositoryCoreContacts",
27-
"sslEnabled": false,
28-
"sslProtocol": "Tls12"
29-
},
30-
"efCore": {
31-
"factory": "SharpRepository.EfCoreRepository.EfCoreConfigRepositoryFactory, SharpRepository.EfCoreRepository",
32-
"dbContextType": "SharpRepository.CoreMvc.ContactContext, SharpRepository.Samples.CoreMvc",
33-
"cachingStrategy": "none",
34-
"cachingProvider": "noCachingProvider"
35-
}
13+
"default": "xml",
14+
"xml": {
15+
"factory": "SharpRepository.XmlRepository.XmlConfigRepositoryFactory, SharpRepository.XmlRepository",
16+
"directory": "xmlDestinationDirectory"
17+
}
3618
},
3719
"cachingProviders": {
3820
"default": "inMemoryProvider",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ArrayOfContact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
3+
<Contact>
4+
<Id>e7f2b7b6a3ee4488aec5d99444ea2a41</Id>
5+
<Name>piero</Name>
6+
<Emails>
7+
<Email>
8+
<Id>0</Id>
9+
<EmailAddress>asd</EmailAddress>
10+
</Email>
11+
</Emails>
12+
</Contact>
13+
</ArrayOfContact>

0 commit comments

Comments
 (0)