There is not uniformity of law on this question, which is usually decided in the period after a death, but before a will is admitted to probate or an executor is appointed (typically in three to five days).
As a result, the legal jurisdiction (usually a country or sub-national state or autonomous region) involved matters a great deal.
For example, Italy used to presume that you did not want organ donation if you didn't execute a document during life saying that you did, and now has the opposite presumption.
Similarly, many jurisdictions used to give a blood relative priority over a same sex partner, but now recognize a civil union or same sex marriage as having priority over a blood relative.
Some jurisdictions give you some say over, for example, whether your body's organs will be donated or your body will be used for medical research. Some have formal documents that can be drafted and there are such things as "negative" provisions that are documents saying who cannot do something with your body. Other jurisdictions, as user6726 suggests, have a fixed priority system for determining who is next of kin and that applies strictly.
Needless to say, a critical issue is how any such directive would be enforced. Obviously you, being dead, can't do that, and documents don't simply crawl out of desk drawers and walk themselves into court houses after your death either. Your wishes will never be enforced unless someone takes it upon themselves at the critical moment, to take action, and in that case, local law determines under what circumstances that person's statement regarding your wishes will be honored.
Often, the person who might step up to take action doesn't learn of your death and of the location of your body until it is too late.
If you die in circumstances where your identity is unknown, or where no relatives can be located and no directives can be located, some public official or whomever else ends up in possession of your body (often a corner) will have to decide for themselves what to do without your input.