Repository: dotnet/runtime
File: src/native/corehost/hostpolicy/deps_resolver.h (C/C++)

Code before:
};

struct deps_resolved_asset_t
{
    deps_resolved_asset_t(const deps_asset_t* asset, pal::string_t&& resolved_path)
        : resolved_path(std::move(resolved_path))
        , m_asset(asset) { }

    const version_t& assembly_version() const
    {
        return m_asset != nullptr ? m_asset->assembly_version : version_t::empty();
    }

    const version_t& file_version() const
    {
        return m_asset != nullptr ? m_asset->file_version : version_t::empty();
    }

    pal::string_t resolved_path;

private:
    const deps_asset_t* m_asset;
};

typedef std::unordered_map<pal::string_t, deps_resolved_asset_t> name_to_resolved_asset_map_t;

class deps_resolver_t
{
public:
    deps_resolver_t(
        const arguments_t& args,
        const fx_definition_vector_t& fx_definitions,
        const pal::char_t* additional_deps_serialized,
        const std::vector<pal::string_t>& shared_stores,
        const std::vector<pal::string_t>& additional_probe_paths,
        deps_json_t::rid_resolution_options_t rid_resolution_options,
        bool is_framework_dependent)
        : m_fx_definitions(fx_definitions)
        , m_app_dir(args.app_root)
        , m_host_mode(args.host_mode)
        , m_managed_app(args.managed_application)
        , m_is_framework_dependent(is_framework_dependent)
        , m_needs_file_existence_checks(false)
    {
        m_fx_deps.resize(m_fx_definitions.size());
        pal::get_default_servicing_directory(&m_core_servicing);

        // If we are using the RID fallback graph and weren't explicitly given a graph, that of
        // the lowest (root) framework is used for higher frameworks.
        deps_json_t::rid_fallback_graph_t root_rid_fallback_graph;
        if (rid_resolution_options.use_fallback_graph && rid_resolution_options.rid_fallback_graph == nullptr)

Review comment (refactor):
`deps_resolved_asset_t` now stores a non-owning `deps_asset_t*`. Please document the required lifetime/ownership expectations (e.g., that the pointed-to `deps_asset_t` must outlive the map entry) to prevent accidental use-after-free in future refactors.

Code after:
    found
};

struct deps_resolved_asset_t
{
    deps_resolved_asset_t(const deps_asset_t* asset, pal::string_t&& resolved_path)
        : resolved_path(std::move(resolved_path))
        , m_asset(asset) { }

    const version_t& assembly_version() const
    {
        return m_asset != nullptr ? m_asset->assembly_version : version_t::empty();
    }

    const version_t& file_version() const
    {
        return m_asset != nullptr ? m_asset->file_version : version_t::empty();
    }

    pal::string_t resolved_path;

private:
    // Asset from a deps.json that was resolved to this path. This should outlive any deps_resolved_asset_t.
    // If null, this entry is not from a deps.json (for example, there is no deps.json) and has no version information.
    const deps_asset_t* m_asset;
};

typedef std::unordered_map<pal::string_t, deps_resolved_asset_t> name_to_resolved_asset_map_t;

class deps_resolver_t
{
public:
    deps_resolver_t(
        const arguments_t& args,
        const fx_definition_vector_t& fx_definitions,
        const pal::char_t* additional_deps_serialized,
        const std::vector<pal::string_t>& shared_stores,
        const std::vector<pal::string_t>& additional_probe_paths,
        deps_json_t::rid_resolution_options_t rid_resolution_options,
        bool is_framework_dependent)
        : m_fx_definitions(fx_definitions)
        , m_app_dir(args.app_root)
        , m_host_mode(args.host_mode)
        , m_managed_app(args.managed_application)
        , m_is_framework_dependent(is_framework_dependent)
        , m_needs_file_existence_checks(false)
    {
        m_fx_deps.resize(m_fx_definitions.size());
        pal::get_default_servicing_directory(&m_core_servicing);

        // If we are using the RID fallback graph and weren't explicitly given a graph, that of