Closed dazraf closed 1 year ago
Hello! Same error here ;/
I managed to bypass this with an arrow function:
.state("service", () => {
return new ResponsibilityDayService(new PrismaClient());
})
.get(
"/user/:id/is-responsible",
async ({ params, store: { service } }) => {
const { id: userId } = params;
return service().isResponsible(Number(userId));
}
)
It's a duplicate of #143
Thank you so so very much @ChristoferMendes and @HKGx!! I was just debugging it and I saw the problem appear in mergician just as @HKGx documented a few hours ago. @ChristoferMendes I will try the arrow function. I want to see if the code caches the result of the function or if it calls it mutiple times. Btw, I've also debugged Mergician and found that this function gets called to get the object keys - the implementation fails to collect functions on the object [EDIT: class instance]. I think there's a better way to do this ...
function getObjectKeys(obj, includeProto = false) {
if (includeProto) {
const keys = [];
for (const key in obj) {
keys.push(key);
}
return keys;
} else {
return Object.keys(obj);
}
}
@dazraf A good writeup, I noticed the same thing.
Closed as it's a duplicate of #143. Btw, @ChristoferMendes I tried your arrow function suggestion. Worked great, thank you. Only thing was that every call to the handler created a new service. I made a lazy evaluation like this:
function lazy<T>(fn: () => T): () => T {
let obj: T
return () => {
if (!obj) {
obj = fn()
}
return obj
}
}
and used it like this:
.state('fooService', lazy(() => new FooService()))
This way, the construction of my service only happens once.
Hello! :wave: :cat: I came across Elysia this weekend and rather excitedly started writing some demo code. Great work - it's very fast and easy to use! However, I came across a bug with dependency injection, as documented here. I've created this "reproducer" example code. Thank you for looking at this issue!