jspuij / RESTier

A turn-key library for building RESTful services
http://odata.github.io/RESTier
Other
2 stars 0 forks source link

What is the benefit of delayed initialization of the model for an ApiBase instance? #11

Open jspuij opened 5 years ago

jspuij commented 5 years ago

Api.GetModelAsync is an asynchronous operation that asynchronously builds a model. This can potentially be an operation that takes a little time, with possibly I/O which makes it a good candidate to execute it asynchronously. Once the model is Built, It's cached internally in the API method and added to the DI container.

This creates multiple problems:

To counter this I propose a simple solution:

This is way better than the SO COOL lazy initialization of the model, which will bite you the way it's implemented now. If you want lazy initialization you can always do that through DI as most DI frameworks can delay instantiation of a dependency until it's necessary and can execute a delegate that calls the GetModelAsync (GenerateModelAsync would be a better name) after instantiation but before it's injected as a dependency.

robertmclaws commented 5 years ago

This is probably one of the main reasons why I wanted to start from scratch for Restier V2 (the version that will be exclusively .NET Core). It is VERY difficult to run multiple Restier instances in the same app currently. I don't think the original developers envisioned this, but I've run into several use cases where it is necessary.

I would suggest being careful about how you proceed based on this information. I HATE the DI implementation in Restier, and you're on the right track. But I'm really nervous about making this many changes so close to shipping V1.

I very much appreciate you doing this, but we need to think about at what point have we fixed DI enough for V!, and at which point do we branch to V2 and rebuild this thing to use Pipes and be Async everywhere and be streamlined AF for the next version.

jspuij commented 5 years ago

I'm always a little wary to start over, because it will introduce a lot of bugs that were fixed before, you lose the collective knowledge that was accumulated in the project. Nonetheless, the code base as it is is arguably worse than when it started in 2014. A lot of the fixes I've done are more or less reversals from stuff done over the years. It does not hurt to take a look at how everything worked 5 years ago and incorporate that into a future design.

However, my preferred route would be the following:

Regarding .NET core only. Is there a pressing reason to do that? Do you mean .NET core or ASP.NET core? .NET core means EF core as well, and there are some major issues open in EF core that prevent us from migrating to EF core.

If you look at https://github.com/aspnet/EntityFrameworkCore/issues?q=is%3Aissue+is%3Aopen+sort%3Acomments-desc there are some serious issues open that do work in EF6, and are postponed indefinitely. It seems the kind of sad state a lot of MS projects are in lately. Dropping support for EF6 will force users to go to EF core.

I'm not completely against, because at some time in the future I will have to move away from EF6 anyway, so I might choose to write a restier provider for NHibernate or LLBLGen, both of which I have better experiences with.

jspuij commented 5 years ago

Wow, I just learned about https://devblogs.microsoft.com/dotnet/announcing-entity-framework-6-3-preview-with-net-core-support/. Seems that isn't a concern anymore.