Skip to content

Commit

Permalink
Code Cleanup (#5)
Browse files Browse the repository at this point in the history
* Regions are evil.
* Add IMergeable to Entity.
* Fix param name in Service ctor.
* Place IService and Service in separate project.
  • Loading branch information
Anthony Sneed committed Feb 13, 2018
1 parent 70ac2c1 commit f9b843b
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Urf.Core.Abstractions;

namespace URF.Core.Abstractions
namespace URF.Core.Abstractions.Services
{
public interface IService<TEntity>: IRepository<TEntity> where TEntity : class
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#region

using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
Expand All @@ -9,16 +7,14 @@
using Urf.Core.Abstractions;
using URF.Core.Abstractions;

#endregion

namespace URF.Core.EF
namespace URF.Core.Abstractions.Services
{
public abstract class Service<TEntity> : IService<TEntity> where TEntity : class
{
protected readonly IRepository<TEntity> Repository;

protected Service(IRepository<TEntity> customerRepository)
=> Repository = customerRepository;
protected Service(IRepository<TEntity> repository)
=> Repository = repository;

public virtual void Attach(TEntity item)
=> Repository.Attach(item);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\URF.Core.Abstractions\URF.Core.Abstractions.csproj" />
</ItemGroup>

</Project>
6 changes: 1 addition & 5 deletions URF.Core.Abstractions/IRepository.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#region

using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using URF.Core.Abstractions;

#endregion

namespace Urf.Core.Abstractions
{
public interface IRepository<TEntity> where TEntity : class
Expand Down
6 changes: 1 addition & 5 deletions URF.Core.EF.Tests/Models/Factory.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#region

using System;
using System;
using System.Collections.Generic;

#endregion

namespace URF.Core.EF.Tests.Models
{
public static class Factory
Expand Down
4 changes: 0 additions & 4 deletions URF.Core.EF.Tests/RepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#region

using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand All @@ -13,8 +11,6 @@
using URF.Core.EF.Tests.Models;
using Xunit;

#endregion

namespace URF.Core.EF.Tests
{
[Collection(nameof(NorthwindDbContext))]
Expand Down
1 change: 1 addition & 0 deletions URF.Core.EF.Tests/Services/CustomerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Urf.Core.Abstractions;
using URF.Core.Abstractions.Services;
using URF.Core.EF.Tests.Models;

namespace URF.Core.EF.Tests.Services
Expand Down
1 change: 1 addition & 0 deletions URF.Core.EF.Tests/Services/ICustomerService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using URF.Core.Abstractions.Services;
using URF.Core.EF.Tests.Models;

namespace URF.Core.EF.Tests.Services
Expand Down
1 change: 1 addition & 0 deletions URF.Core.EF.Tests/URF.Core.EF.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\URF.Core.Abstractions.Services\URF.Core.Abstractions.Services.csproj" />
<ProjectReference Include="..\URF.Core.Abstractions.Trackable\URF.Core.Abstractions.Trackable.csproj" />
<ProjectReference Include="..\URF.Core.Abstractions\URF.Core.Abstractions.csproj" />
<ProjectReference Include="..\URF.Core.EF.Trackable\URF.Core.EF.Trackable.csproj" />
Expand Down
10 changes: 7 additions & 3 deletions URF.Core.EF.Trackable/Entity.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using TrackableEntities.Common.Core;

namespace URF.Core.EF.Trackable
{
public abstract class Entity : ITrackable
public abstract class Entity : ITrackable, IMergeable
{
[NotMapped]
public TrackingState TrackingState { get; set; }

[NotMapped]
public ICollection<string> ModifiedProperties { get; set; }

[NotMapped]
public Guid EntityIdentifier { get; set; }
}
}
}
6 changes: 6 additions & 0 deletions URF.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "URF.Core.EF.Tests", "URF.Co
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "URF.Core.EF.Trackable", "URF.Core.EF.Trackable\URF.Core.EF.Trackable.csproj", "{E48C7073-967B-45C7-A38E-2907B9A6B40D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "URF.Core.Abstractions.Services", "URF.Core.Abstractions.Services\URF.Core.Abstractions.Services.csproj", "{DB7FF41B-F2ED-44E7-A40E-199BF583981C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -44,6 +46,10 @@ Global
{E48C7073-967B-45C7-A38E-2907B9A6B40D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E48C7073-967B-45C7-A38E-2907B9A6B40D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E48C7073-967B-45C7-A38E-2907B9A6B40D}.Release|Any CPU.Build.0 = Release|Any CPU
{DB7FF41B-F2ED-44E7-A40E-199BF583981C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DB7FF41B-F2ED-44E7-A40E-199BF583981C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DB7FF41B-F2ED-44E7-A40E-199BF583981C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DB7FF41B-F2ED-44E7-A40E-199BF583981C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit f9b843b

Please sign in to comment.