Hi,
Consider the following code.
var proposal = await _travelOfferPriceProposalRepository.GetAll()
.Include(b => b.TravelOfferPriceProposalElements).ThenInclude(b => b.TravelElement)
.Include(b => b.TravelOfferPriceProposalGroups).ThenInclude(b => b.TravelOfferPriceProposalElements).ThenInclude(b => b.TravelElement)
.FirstOrDefaultAsync(b => b.Id == id);
///
// This code will automatically do hard delete the data we have. Without any notification.
// Due to UnitOfWork.
///
proposal.TravelOfferPriceProposalElements = proposal.TravelOfferPriceProposalElements
.Where(b => b.TravelOfferPriceProposalGroupId == null && b.TravelOfferPriceProposalId == id).ToList();
///
///
// Need to use this instead
var test = ObjectMapper.Map<TravelOfferPriceProposalDto>(proposal);
test.TravelOfferPriceProposalElements = test.TravelOfferPriceProposalElements
.Where(b => b.TravelOfferPriceProposalGroupId == null && b.TravelOfferPriceProposalId == id).ToList();
return test;
As you can see our software team has made the logical error of filter out data and storing it on the same entity, causing it to delete the actual data from our database instead of just doing a filterd get.
We understand the issue, however the above code causes a hard delete on our records. Despite the fact that TravelOfferPriceProposalElement is a full audited entity. Should that not be a soft delete?
Is this a issue/shortcomming of the ISoftDelete interface combined with EFCore or is this normal behaviour? If this is normal how can we log hard deletes for fullauditedentities on a application level?
We believe our team has made this mistake on multiple appservices.
Thanks in advance for any advice given.
Hi,
I noticed in the latest version of aspnetzero that lazy loading is still not enabled. The proxy library is not yet implemented. I managed to implement lazy loading myself in my project but now i'm starting to doubt if that's a good idea.
Is there any reason why aspnetzero has not yet implemented lazy loading in the .netcore version? Missing key features or something? (For example any nav property now Must be virtual, otherwise it won't work at all)
Thx for the info.
Hi,
I want to create a custom repository. This is what i've done so far.
namespace TravelNote.MyGloby.Localization.UserDefined
{
public interface ILocalizedRepository<TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey>
where TEntity : class, IEntity<TPrimaryKey>
{
}
public interface ILocalizedRepository<TEntity> : ILocalizedRepository<TEntity, int>
where TEntity : class, IEntity<int>
{
}
namespace TravelNote.MyGloby.EntityFrameworkCore.Repositories
{
public class LocalizedRepository<TEntity, TPrimaryKey> : MyGlobyRepositoryBase<TEntity, TPrimaryKey>, ILocalizedRepository<TEntity, TPrimaryKey>
where TEntity : class, IEntity<TPrimaryKey>
{
public LocalizedRepository(IDbContextProvider<MyGlobyDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
}
public class LocalizedRepository<TEntity> : LocalizedRepository<TEntity, int>
where TEntity : class, IEntity<int>
{
public LocalizedRepository(IDbContextProvider<MyGlobyDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
}
}
private readonly ILocalizedRepository<TravelType,int> _travelRepository;
private readonly IUserLocalizerManager _locMan;
public TravelTypeAppService(ILocalizedRepository<TravelType,int> travelRepository, IUserLocalizerManager locMan)
{
_travelRepository = travelRepository;
_locMan = locMan;
}
My error when running
ERROR 2018-04-15 17:35:54,710 [4 ] Mvc.ExceptionHandling.AbpExceptionFilter - Can't create component 'TravelNote.MyGloby.TravelOptions.TravelTypeAppService' as it has dependencies to be satisfied.
'TravelNote.MyGloby.TravelOptions.TravelTypeAppService' is waiting for the following dependencies:
- Service 'TravelNote.MyGloby.Localization.UserDefined.ILocalizedRepository`2[[TravelNote.MyGloby.TravelOption.TravelType, TravelNote.MyGloby.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered.
Castle.MicroKernel.Handlers.HandlerException: Can't create component 'TravelNote.MyGloby.TravelOptions.TravelTypeAppService' as it has dependencies to be satisfied.
'TravelNote.MyGloby.TravelOptions.TravelTypeAppService' is waiting for the following dependencies:
- Service 'TravelNote.MyGloby.Localization.UserDefined.ILocalizedRepository`2[[TravelNote.MyGloby.TravelOption.TravelType, TravelNote.MyGloby.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]' which was not registered.
at Castle.MicroKernel.Handlers.DefaultHandler.AssertNotWaitingForDependency()
at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy)
at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
at Castle.Windsor.MsDependencyInjection.ScopedWindsorServiceProvider.GetServiceInternal(Type serviceType, Boolean isOptional) in D:\Github\castle-windsor-ms-adapter\src\Castle.Windsor.MsDependencyInjection\ScopedWindsorServiceProvider.cs:line 55
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.AspNetCore.Mvc.Controllers.ServiceBasedControllerActivator.Create(ControllerContext actionContext)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextExceptionFilterAsync>d__23.MoveNext()
I've also tried manualy registering my repository in the EfCoreAppModule.
But that doesn't seem to help. What am i forgeting to make this work? Thanks for any advice.
IocManager.IocContainer.Register(Component.For(typeof(ILocalizedRepository<>)).ImplementedBy(typeof(LocalizedRepository<>)).LifestyleTransient());
using this tutorial i came across an issue i can't figure out. : [https://aspnetboilerplate.com/Pages/Documents/Articles/Aspect-Oriented-Programming-using-Interceptors/index.html])
When i call my api, my intercept constructor is hit but never the method void Intercept(IInvocation invocation). When i use unit testing, my interceptor is called perfectly. What am i doing wrong?
I've debugged extensivly and on app startup the registar class is called for every application method.
my code
public static class MeasureDurationInterceptorRegistrar
{
public static void Initialize(IKernel kernel)
{
kernel.ComponentRegistered += Kernel_ComponentRegistered;
}
private static void Kernel_ComponentRegistered(string key, IHandler handler)
{
if (typeof(IApplicationService).IsAssignableFrom(handler.ComponentModel.Implementation))
{
handler.ComponentModel.Interceptors.Add
(new InterceptorReference(typeof(MeasureDurationInterceptor)));
}
}
}
public class MeasureDurationInterceptor : IInterceptor
{
public ILogger Logger { get; set; }
public MeasureDurationInterceptor()
{
Logger = NullLogger.Instance;
}
public void Intercept(IInvocation invocation)
{
//Before method execution
var stopwatch = Stopwatch.StartNew();
//Executing the actual method
invocation.Proceed();
//After method execution
stopwatch.Stop();
Logger.InfoFormat(
"MeasureDurationInterceptor: {0} executed in {1} milliseconds.",
invocation.MethodInvocationTarget.Name,
stopwatch.Elapsed.TotalMilliseconds.ToString("0.000")
);
}
}
public class MyGlobyApplicationModule : AbpModule
{
public override void PreInitialize()
{
//Adding authorization providers
Configuration.Authorization.Providers.Add<AppAuthorizationProvider>();
//Adding custom AutoMapper configuration
Configuration.Modules.AbpAutoMapper().Configurators.Add(CustomDtoMapper.CreateMappings);
////register custom interceptor for tenant control
//TenantAuthorizationInterceptorRegistrar.Initialize(IocManager.IocContainer.Kernel);
MeasureDurationInterceptorRegistrar.Initialize(IocManager.IocContainer.Kernel);
}
Hi,
Our tenant will have a entity "Customer". We want to give that customer login capabilties. Perfarably a different login form that the form a regular user logs in.
When that customer log's in he should see a complete custom designed page with all the information relating to that customer. So no navigation bar, of a different navigation bar and so on.
We use ASP.NET CORE and angular setup.
My question is. How do we best tackle this problem? Do we create a property "User" on that Customer entity with a predefined role so we can restrict their access? Or..?
I've you need any more information let me know. Thx Jonas.