Since I teach this topic to dealer techs for my employer, let me give a quick clarification.
DEF has a definite shelf life and you would be wise to carry your own, but don't buy huge quantities so you have quality DEF to use. Be careful with it and store it in plastic containers with tight fitting, leak-proof lids. It will quickly corrode any metal it comes in contact with. There are kits to test the DEF quality, but I'm sure you don't want to do that at a fuel station. The advice was good when you were told the DEF at a fuel station is questionable - unless you are familiar with their practices. Fill your DEF tank when it gets low so that the DEF doesn't sit in the tank too long. But don't let it run out. Your engine performance will be derated, and eventually won't be able to be restarted (until the code is cleared by a dealer tech) if you let it run out enough times. So be vigilant.
DEF was introduced for on-highway diesel engines a few years back, as the best technology so far for meeting the EPA's Tier 4 Final emissions regulations. Tier 4 Interim introduced the DPF (Diesel Particulate Filter) and EGR (Exhaust Gas Recirculation), about 2004.
EGR recirculates cooled exhaust gasses that mix with charge air for combustion. Diesel engines naturally run colder than gas engines, so not all the fuel burns during combustion. (That's where the distinctive diesel smell came from in older engines.) Recirculating the exhaust ensures nearly all fuel is burned.
The DPF captures the soot in diesel exhaust and converts it to ash during the regeneration process. Exhaust temperatures must be high enough, though, to facilitate regeneration. Most small engines (less than 9 liters) employ passive regeneration using a diesel exhaust backpressure valve - essentially restricting the exhaust, which elevates engine and exhaust temperatures high enough to achieve regeneration.
The DEF is then injected into the exhaust stream after the DPF, but before the SCR (Selective Catalytic Reduction) canister. The SCR is a second filter of sorts, made from rare earth elements (platinum, palladium, etc). The DEF and the SCR filter combine to create a chemical reaction that removes NOx (Nitrous Oxide) from the exhaust. There is a NOx sensor before and after the SCR and a dedicated control module determines how much DEF needs to be injected.
The result is the exhaust exiting the SCR (and your tailpipe) consists of only carbon dioxide and water vapor - cleaner than the air the engine is taking in - but laden with CO2.
That's the short course - and probably more than most want to know.
2015 Jay Flight 32RLDS Elite
2012 Chevy 2500HD Crew Cab LTZ (6.6L Duramax/Allison)
Equalizer Hitch (1200# bars)