Giter Club home page Giter Club logo

Comments (4)

poletti-marco avatar poletti-marco commented on September 25, 2024

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.

AndreiGS avatar AndreiGS commented on September 25, 2024

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.

poletti-marco avatar poletti-marco commented on September 25, 2024

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.

AndreiGS avatar AndreiGS commented on September 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.