diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index d2fc39d95..ebd674579 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -1,17 +1,15 @@ - +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; +using Microsoft.eShopOnContainers.Services.Catalog.API.Model; +using Microsoft.eShopOnContainers.Services.Catalog.API.ViewModel; +using Microsoft.Extensions.Options; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers { - using Extensions.Options; - using Microsoft.AspNetCore.Mvc; - using Microsoft.EntityFrameworkCore; - using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; - using Model; - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - using ViewModel; - [Route("api/v1/[controller]")] public class CatalogController : ControllerBase { @@ -22,6 +20,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers { _context = context; _settings = settings; + + ((DbContext)context).ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; } // GET api/v1/[controller]/items/[?pageSize=3&pageIndex=10] @@ -30,7 +30,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers public async Task Items(int pageSize = 10, int pageIndex = 0) { var totalItems = await _context.CatalogItems - .LongCountAsync(); + .LongCountAsync(); var itemsOnPage = await _context.CatalogItems .OrderBy(c=>c.Name) diff --git a/src/Services/Catalog/Catalog.API/project.json b/src/Services/Catalog/Catalog.API/project.json index 45a732033..67d3b95cd 100644 --- a/src/Services/Catalog/Catalog.API/project.json +++ b/src/Services/Catalog/Catalog.API/project.json @@ -1,4 +1,9 @@ { + "buildOptions": { + "emitEntryPoint": true, + "preserveCompilationContext": true, + "debugType": "portable" + }, "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0", @@ -23,9 +28,6 @@ "Microsoft.EntityFrameworkCore.Design": "1.1.0", "Swashbuckle": "6.0.0-beta902" }, - "tools": { - "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final" - }, "frameworks": { "netcoreapp1.1": { "imports": [ @@ -34,16 +36,6 @@ ] } }, - "buildOptions": { - "emitEntryPoint": true, - "preserveCompilationContext": true, - "debugType": "portable" - }, - "runtimeOptions": { - "configProperties": { - "System.GC.Server": true - } - }, "publishOptions": { "include": [ "wwwroot", @@ -56,6 +48,14 @@ "Dockerfile" ] }, + "runtimeOptions": { + "configProperties": { + "System.GC.Server": true + } + }, "scripts": {}, + "tools": { + "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final" + }, "userSecretsId": "aspnet-Catalog.API-20161122013618" } \ No newline at end of file diff --git a/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs b/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs new file mode 100644 index 000000000..40e587683 --- /dev/null +++ b/src/Services/Ordering/Ordering.Domain/SeedWork/ValueObject.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork +{ + public abstract class ValueObject + { + protected static bool EqualOperator(ValueObject left, ValueObject right) + { + if (ReferenceEquals(left, null) ^ ReferenceEquals(right, null)) + { + return false; + } + return ReferenceEquals(left, null) || left.Equals(right); + } + + + protected static bool NotEqualOperator(ValueObject left, ValueObject right) + { + return !(EqualOperator(left, right)); + } + + + protected abstract IEnumerable GetAtomicValues(); + + + public override bool Equals(object obj) + { + if (obj == null || obj.GetType() != GetType()) + { + return false; + } + ValueObject other = (ValueObject)obj; + IEnumerator thisValues = GetAtomicValues().GetEnumerator(); + IEnumerator otherValues = other.GetAtomicValues().GetEnumerator(); + while (thisValues.MoveNext() && otherValues.MoveNext()) + { + if (ReferenceEquals(thisValues.Current, null) ^ ReferenceEquals(otherValues.Current, null)) + { + return false; + } + if (thisValues.Current != null && !thisValues.Current.Equals(otherValues.Current)) + { + return false; + } + } + return !thisValues.MoveNext() && !otherValues.MoveNext(); + } + + + public override int GetHashCode() + { + return GetAtomicValues() + .Select(x => x != null ? x.GetHashCode() : 0) + .Aggregate((x, y) => x ^ y); + } + + public ValueObject GetCopy() + { + return this.MemberwiseClone() as ValueObject; + } + } +}