Comments (4)
Hi, I'm not familiar with Qt so I'm going to need more information on what you're doing.
Can you please share an (ideally minimal) example code and commands that can be used to reproduce the issue?
See https://stackoverflow.com/help/minimal-reproducible-example
from fruit.
Let's say I have this repository, the base repository is just a simple template repository with basic functionality in it
class IUserRepository : public BaseRepository<User, uint16_t>
{
public:
~IUserRepository() override = default;
virtual std::optional<User> FindByName(const std::string& name) = 0;
};
This is the implementation header:
class UserRepository : public IUserRepository
{
public:
INJECT(UserRepository()) = default;
~UserRepository() override = default;
std::optional<User> FindByName(const std::string& name) override;
};
fruit::Component<IUserRepository> getUserRepositoryComponent();
And this is the implementation:
std::optional<User> UserRepository::FindByName(const std::string& name)
{
using namespace sqlite_orm;
try {
auto guard = k_Database.transaction_guard(); // calls BEGIN TRANSACTION and returns guard object
auto entity = k_Database.get_all<User>(where(c(&User::GetName) == name)); // exception is thrown here, guard calls ROLLBACK in its destructor
guard.commit();
if (entity.empty())
{
return std::nullopt;
}
return std::make_optional(std::move(entity[0]));
}
catch (...) {
return std::nullopt;
}
}
fruit::Component<IUserRepository> getUserRepositoryComponent()
{
return fruit::createComponent().bind<IUserRepository, UserRepository>();
}
When doing this:
fruit::Injector<IUserRepository> inj{ getUserRepositoryComponent };
IUserRepository* service(inj);
auto rsp = service->FindByName("Iris");
in the backend app it works fine, but the exact same code used in the main.cpp of the qQTproject throws an error when initializing the injector, maybe because it cannot create the binding? I do not think it is a linking error because it happens even if I move all the backend files into the QT project.
Thank you for the help!
from fruit.
I don't see anything wrong in the code you provided, so either the issue is an undefined behavior elsewhere in your code (the code provided has several references to things not defined in the provided code) or a platform/installation issue.
What OS are you using? Fruit supports Linux, windows, MacOS.
How did you install Fruit? From source, with binary packages, etc.
If from source, did you build fruit using cmake or something else?
What version of Fruit are you using?
What compiler are you using? GCC, clang, etc.
You mentioned that there's an error when creating the injector, can you please provide the exact error?
from fruit.
Sorry for the late response. I am using Windows 10 x64 with Visual Studio 2022 and Fruit was installed using vcpkg and the version is the latest. I cannot provide the exact error because I had to remove Fruit from the project, but it was that it cannot access some memory address.
from fruit.
Related Issues (20)
- Fruit does not build in Visual Studio Versions 2019, 2022 or 2022 Preview with CMake HOT 8
- what should I do to use a string as an annotion of some bind? HOT 3
- VS2022 Just My Code for Fruit Library fails using CMAKE HOT 6
- Create a fruit::Component by iterating over a list of fruit::Components HOT 7
- Can fruit be used with C language? HOT 2
- Handling lifetimes HOT 6
- Providing non-injected arguments to DI Objects HOT 14
- Build fails with Visual Studio 2022 with C++20 HOT 8
- Factories with reference types broken in fruit 3.7.0
- Generic binding? HOT 2
- Defining Factory Functions for Objects with Multiple Constructors HOT 11
- Replace boost HOT 1
- Creating Collections of DI Objects HOT 3
- [Suggestion] ExtractFirstError meta function SHOULD be non-error safe HOT 2
- Can no longer build examples in VS2022 Preview built by Visual Studio, VS CMake builds OK HOT 7
- Examples miss virtual dtor
- bindInstance with copy HOT 13
- Understanding Compiler error messages in Fruit HOT 6
- Adding a special constructor to one implementation of an interface HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fruit.